hi
I have a problem. Im creating a game and basically i have 2 boxes. if these boxes loook each other from the side that i define (i put a plane to their surfaces) then a button appears… If i click to this button one piece moves to another until it collides and it doesnt stop until it reaches to the middle of the other cube…
Im detecting hits (raycasting) from my first plane to another object plane… IF hit happens then i add them to an array. If there are 2 objects in array button shows up… I tried many things including deactivating script but then there are other problems shows up… Like i cannot use raycasting again cuz i deactivate it…
Here is my code:
//This is how i move from one object to another
Transform a = gameTag.gameO[0].transform;
Transform b = gameTag.gameO[1].transform;
a.position = Vector3.MoveTowards(a.position,b.position, moveSpeed * Time.deltaTime);
//this is my raycast system. Im putting this script to each of my objects…
RaycastHit hit;
if (flagTrigger==false)
{
if (Physics.Raycast(transform.position, -transform.forward, out hit, 10))
{
var forward = transform.TransformDirection(Vector3.forward) * 10;
arrayListForSelectables gameTag = GameObject.FindGameObjectWithTag("TheGame").GetComponent<arrayListForSelectables>();
if (hit.transform.tag == "Select")
{
if (!gameTag.gameO.Contains(this.gameObject))
gameTag.gameO.Add(this.gameObject);
}
else
{
gameTag.gameO.Remove(this.gameObject);
}
}
//Lastly here my kind of trigger system
void OnTriggerEnter(Collider other)
{
Raycast u = other.GetComponent<Raycast>();
if (u != null)
{
arrayListForSelectables gameTag = GameObject.FindGameObjectWithTag("TheGame").GetComponent<arrayListForSelectables>();
if (enabled && gameTag.gameO.Contains(this.gameObject))
{
gameTag.gameO.Remove(this.gameObject);
flagTrigger = true;
//enabled = false;
}
}
}
I commented out the enabled part for now… If i use it i cannot use the same script again… I know the problems but i donno the answer for it… Any help please…