Script not detecting when player is facing left.

Updated on November 9, 2017 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on November 5, 2017

My projectile is always moving right and I have deducted that that is because the script that moves the projectile is always saying that the player is facing right, even when he is not. The PlatformerCharacter2D script is detecting it correctly.

using UnityEngine;
using UnityStandardAssets._2D;
public class MoveTrail : MonoBehaviour {
    public int moveSpeed = 150;
    public GameObject player;
    void Update () {
        if (player.GetComponent<PlatformerCharacter2D>().m_FacingRight == false)
        {
            Debug.Log("FacingRight = False");
            transform.Translate(-1, 0, 0 * Time.deltaTime * moveSpeed);
            Destroy(gameObject, 1);
        }
        else
        {
            Debug.Log("FacingRight = True");
            transform.Translate(1, 0, 0 * Time.deltaTime * moveSpeed);
            Destroy(gameObject, 1);
        }
    }
}
  • Liked by
Reply
1 on November 9, 2017

Did you try printing the the value of “player.GetCOmponent<PLatformerCharacter2D>().m_FacingRight” instead of “FacingRight = true” or false in the “MoveTrail” script.

on November 9, 2017

i tried that and nothing changed

 

Show more replies
  • Liked by
Reply
Cancel