using UnityEngine;
using System.Collections;
public class Script: MonoBehaviour
{
public GameObject [] GO = new GameObject [4];
private bool isClicked;
private int moveGO;
void Update ()
{
for(int i=0 ; i<4; i++)
{
if(GO *!= null)*
-
{* -
if(isClicked)* -
{*
GO.transform.localPosition = new Vector3(GO.transform.localPosition.x + avatarPosition, GO_.transform.localPosition.y, GO*.transform.localPosition.z);*_
* isClicked = false;*
* }*
_ if(GO*.transform.localPosition.x > 8)
GO.transform.localPosition = new Vector3(-4, GO.transform.localPosition.y, GO.transform.localPosition.z);*_
_ if(GO*.transform.localPosition.x < -4)
GO.transform.localPosition = new Vector3(8, GO.transform.localPosition.y, GO.transform.localPosition.z);
}
}
}*_
* void OnGUI()*
* {*
* for(int i=0; i<4; i++)*
* {*
_ if(GO*.active == true)
{
//Next gameObject*
* if(GUI.Button(new Rect(600, 200, 50, 50), “>”))
{
isClicked = true;
moveGO= moveGO+ 4;
}*_
* //Previous gameObject*
* if(GUI.Button(new Rect(100, 200, 50, 50), “<”))*
* {*
* isClicked = true;*
* moveGO= moveGO- 4;*
* }*
}
*} *
There are 4 gameobjects and i have stored them in an array. On button click i want these objects to move by unit 4. Whenever i am pressing the buttons only 1 game object is moving because immediately i am making isclicked as false. I know this is easy but somehow i am not able to solve. Please help
A general note: Please make it a habit to mark the correct answers whenever you receive one. Cheers!
– GuyTidharWould you please mark the answer as correct if it is so?
– GuyTidharlet me check if it is working or not... i think it will work.. but let me check first then i will mark it as correct
– united4lifeit is still not working.... after the GO reaches 8 the GOs overlap with eachother. I think i am doing something wrong in these lines if(GO*.transform.localPosition.x > 8)* <em>GO<em>.transform.localPosition = new Vector3(-4, GO_.transform.localPosition.y, GO*.transform.localPosition.z);_</em></em> <em><em><em>_if(GO.transform.localPosition.x < -4)</em></em></em> <em><em><em><em><em>GO<em>.transform.localPosition = new Vector3(8, GO.transform.localPosition.y, GO.transform.localPosition.z);*_</em></em></em></em></em></em>
– united4lifeyeah it is working fine. Thanks for your reply
– united4life