Welcome, I would like to make a high jump and speed zones in my project.
I am looking for the best way to do this.
I was tried to make this by changing extraHeight variable in CharacterMotor script from other script attached to trigger using GetComponent but I received:
Object reference not set to an instance of an object
What is wrong? What is the best way to do this?
Here is my part of script:
void OnTriggerEnter(Collider other){
if (other.gameObject.tag == "Player"){
Debug.Log("Enter!"); //work fine
GetComponent<CharacterMotor>().jumping.extraHeight=12.0f; //didn't work
}
}
public class jump : MonoBehaviour {
CharacterMotor playerScript;
// Use this for initialization
void Start () {
playerScript = (CharacterMotor)GameObject.FindGameObjectWithTag("Player").GetComponent("CharacterMotor");
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider other) {
if (other.gameObject.tag == "Player"){
Debug.Log("Enter!"); //work fine
playerScript.jumping.baseHeight=10;
}
}
void OnTriggerExit(Collider other) {
if (other.gameObject.tag == "Player"){
Debug.Log("Exit!"); //work fine
playerScript.jumping.baseHeight=1;
}
}
void OnTriggerStay(Collider other) {
if (other.gameObject.tag == "Player"){
Debug.Log("Stay!"); //work fine
}
}
}
Here is my solution but could anybody check this?
It works but I don’t know why I must use this line: