l have 3 objects and 2 scripts. This is what first script does: When object A (Player) collides with object B (Ground), it sets bool called collided to true.
using UnityEngine;
using System.Collections;
public class changegrav : MonoBehaviour {
public bool collided;
void Update () {
Debug.Log (collided); // I USED THIS TO CHECK IF SCRIPT WORKS PROPERLY, AND IT WORKED
}
void OnTriggerEnter (Collider other)
{
if (other.gameObject.name == "tground") {
collided = true;
}
}
void OnTriggerExit (Collider other)
{
if (other.gameObject.name == "tground") {
collided = false;
}
}
}
And my second script is attached to object C, and it supposed to play an animation if collided = true:
using UnityEngine;
using System.Collections;
public class changegrav2 : MonoBehaviour {
public GameObject objectOne;
private changegrav otherScript;
private bool collided;
void Start (){
otherScript = objectOne.GetComponent<changegrav> ();
collided = otherScript.collided;
}
}
After realizing that its not working, l decided to remove Debug.Log from the first script and add it to the second script and l realized even if collided in first script is true, Debug.Log in second script always prints collided as FALSE . Its probably because l didn’t called collided bool from script 1 to script 2 properly…maybe… ldk.
If you have any ideas, plz let me know.