On the below code, the object “Boomerang” should follow a “Player” and rotate on the Y axis (when the player go left or right).
But the both lines:
→ transform.eulerAngles = new Vector2 (0, 0);
→ transform.eulerAngles = new Vector2 (0, 180);
…does not seem to do anything.
The boomerang does not rotate at all, and in Transform → Rotation → Y keep display “0”.
In the console, the two print return:
0
UnityEngine.Monobehaviour:print(Object)
1
UnityEngine.Monobehaviour:print(Object)
Any idea?
Below my code:
using UnityEngine;
using System.Collections;
public class BoomerangController : MonoBehaviour {
public Animator anim;
public PlayerController player;
// Use this for initialization
void Start () {
anim = GetComponent<Animator> ();
}
void Update () {
Physics2D.IgnoreCollision (player.collider2D, collider2D);
if(player.getDirection() == "right"){
transform.eulerAngles = new Vector2 (0, 0);
print (transform.rotation.y);
} else if (player.getDirection() == "left"){
transform.eulerAngles = new Vector2 (0, 180);
print (transform.rotation.y);
}
}
void LateUpdate(){
transform.position = new Vector2 (player.transform.position.x, player.transform.position.y - 0.1f);
}
}