Hi there,
Well, I have spent 4 hours tonight researching and reading Unity Answers to try and find a solution to a SIMPLE problem. Maybe my head is just too stuffed with information today.
I have an array of GameObjects which I access a script attached to each one of those gameobjects. These scripts have animations attached to them.
I want to be able to access the script on a button click, and on the same button click disable the gameobject. But, I want the script to continue playing after the button click, just do nothing upon a second button click. However the button has to remain active for all new objects added to the array.
using UnityEngine;
using System.Collections;
public class GameController : MonoBehaviour {
GameObject[] bombs;
GameObject[] explosions;
private InventoryControl inventoryControl;
void Start ()
{
GameObject inventoryControllerObject = GameObject.FindGameObjectWithTag ("GameController");
inventoryControl = inventoryControllerObject.GetComponent<InventoryControl> ();
}
void Update ()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast (ray, out hit, 5)) {
Quaternion q = Quaternion.FromToRotation(transform.up, hit.normal);
Instantiate (inventoryControl.activeBomb, hit.point+hit.normal*0.01f, q);
}
}
}
public void explodeBomb()
{
bombs = GameObject.FindGameObjectsWithTag ("Bombs");
explosions = GameObject.FindGameObjectsWithTag ("Explosions");
for (int i=0; i<explosions.Length; i++)
{
explosions *.GetComponent<Detonator> ().Explode ();*
-
foreach (GameObject Explosions in explosions)*
-
{*
-
//I know something goes here to do what I want!!!1*
-
}*
-
for(int i=0; i<bombs.Length; i++)*
-
{*
_ Destroy(bombs*);_
_ }_
_ }_
_}*_
I’m losing my mind! It seems like this should be easy.
As always, you guys are awesome, and I know someone smarter than me will have a quick solution.
Thanks,
Cnote