Hi, Unity Community! It seems as though my script does not work on multiple objects. The script is attached to multiple planes that suppose to move according to their original positions and the position of the player. But this only works for one of the planes. The other duplicates does not work at all. It seems like the planes stack on top of the original. Can anyone tell me why this is happening?
var distance : float = 140.0;
private var startPos : Vector3;
private var player : Transform;
private var mask : Transform;
private var centerPt : Vector3;
function Start(){
startPos = new Vector3(transform.position.x, 0 , transform.position.z);
player = GameObject.FindGameObjectWithTag("Player").transform;
mask = GameObject.Find("Mask").transform;
}
function Update(){
transform.position.y = mask.transform.position.y + 11;
if(Vector3.Distance(startPos,player.position) > 140){
var movement = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
var newPos = transform.position + movement;
var offset = newPos - centerPt;
gameObject.transform.position = (player.transform.position + startPos) / 2;
transform.position = player.transform.position + -Vector3.ClampMagnitude(player.transform.position - centerPt, distance);
transform.position.y = mask.transform.position.y + 11;
}
else{
transform.position = startPos;
transform.position.y = mask.transform.position.y + 11;
}
}