I don t get to rotate an object about a single axis, so this points to another object.
I have a 2D application with an arrow in the middle of the screen and a ball up in the left side, i want the arrow to follow the ball as it continues moving. The ball moves in X and Y and the arrow should rotate only in Z. Anyone knows how to fix that?
using UnityEngine;
using System.Collections;
public class Arrow : MonoBehaviour {
public Transform ball;//set from inspector
public float speed = 3f;
void Update(){
//rotate to look at the ball
transform.LookAt(ball.position);
//Maybe you dont need this
transform.Rotate(new Vector3(0,-90,0),Space.Self);//correcting the original rotation
//move towards the ball
if (Vector3.Distance(transform.position,ball.position)>0.1f){//move if distance from ball is greater than 0.1f
transform.Translate(new Vector3(speed* Time.deltaTime,0,0) );
}
}
}