I know what is happening, probably even why, but i’m unsure how to solve it.
I have an object spawner, an object and a player. On my player, there is a script which controls my ability to move which includes a “can move” bool.
Now when my spawned object collides with my player my played is supposed to be stunned by deactivating the “can move” property in the script of my player.
This is the code,
public class FallingObjectControl : MonoBehaviour {
//Get the Character
public GameObject playerObject;
public bool Stunned;
public float StunnedFor = 5.0f;
// Use this for initialization
void Start () {
}
void FixedUpdate()
{
if (Stunned)
{
Debug.Log("Stunned");
// HandleStun();
StartCoroutine(HandleStun());
}
}
void Update () {
}
private IEnumerator HandleStun()
{
//Stunned, De activate movement
playerObject.GetComponent<CharacterHorizontalMovement>().AbilityPermitted = false;
yield return new WaitForSeconds(StunnedFor);
playerObject.GetComponent<CharacterHorizontalMovement>().AbilityPermitted = true;
Stunned = false;
}
Problem
My problem is not the inability to access variables from another script, I think it’s with assigning the correct game object.
The problem I am having is that, if I select the FallingObject prefab, I cannot drag my player in my hierarchy view to the public game object. I believe I read that was because you can have different game objects in different levels.
If I drag the prefab from my player character into the public field for the game object, it accepts it, the code is run and “Stunned” shows up in my debug log, but the bool is NOT set to false making me think that the game object that I dragged in is not the same game object as my player.
HOWEVER, if i drag out the falling object to my hierarchy and drag the game object from my hierarchy into public field, it works perfectly when it collides with that single object.
I would like some help in resolving this, from my testing it seems to be some issue between accessing the right game object, but im not sure what game object it is expecting to work.