I have 2 cubes with the following script applied. The problem is when i swipe one object to rotate it it rotates both.
Can someone tell me why?
var targetItem : GameObject;
/********Rotation Variables*********/
var rotationRate : float = 1.0;
private var wasRotating;
var hit: RaycastHit;
private var layerMask = (1 << 8) | (1 << 2);
function Start()
{
layerMask =~ layerMask;
}
function FixedUpdate()
{
if (Input.touchCount > 0)
{ // If there are touches...
var theTouch : Touch = Input.GetTouch(0); // Cache Touch (0)
var ray = Camera.main.ScreenPointToRay(theTouch.position);
if(Physics.Raycast(ray,hit,50,layerMask))
{
if(Input.touchCount == 1)
{
if (theTouch.phase == TouchPhase.Began)
{
wasRotating = false;
}
if (theTouch.phase == TouchPhase.Moved)
{
targetItem.transform.Rotate(0, theTouch.deltaPosition.x * rotationRate,0,Space.World);
wasRotating = true;
}
}
}
}
}