-2

So far my script is below. I am attempting to create another Collider part to the script, I am attempting to make it so when you collide with Lava, which has a Tag named lava, the player will die. However, I can't get it to call for the die function and I also can't use OnTriggerEnter(collider,other) as it gives me an error.

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour
// Player Movement Start
{

    public float speed;

    private Rigidbody rb;

    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    void FixedUpdate()
    {
        float moveHorizontal = Input.GetAxis("Horizontal");
        float moveVertical = Input.GetAxis("Vertical");

        Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

        rb.AddForce(movement * speed);
    }
            //End of Player Movement Script
    //Pickups Script
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("Pick Up"))
        {
            other.gameObject.SetActive(false);
        }
    }
        //End of Pickups Script
    //Health and Death Script
    public float health;                
    public GameObject Ragdoll;             

    public void TakeDamage(float dmg){
        health -= dmg;

        if (health <= 0) {
            Die();
        }
    }
    public void Die() {
        Application.LoadLevel(Application.loadedLevel);

    }

 }
//End of Health and Death script
Kędrzu
  • 2,385
  • 13
  • 22

1 Answers1

0

According to the answer here,

The access level for class members and struct members, including nested classes and structs, is private by default.

With this logic, and knowing that OnTriggerEnter(...) must be called from outside of your MonoBehaviour, you should probably explicitly make it public

Also, you say you are trying to run your Die(...) method from the OnTriggerEnter(...) function, but i dont see that in your code, it should look as follows:

public void OnTriggerEnter(Collider other)
{
    switch (other.tag)
    { 
        case "Pick Up": other.gameObject.SetActive(false);
            break;
        case "Lava": Die();
            break;
    }
}
Community
  • 1
  • 1
maraaaaaaaa
  • 7,749
  • 2
  • 22
  • 37