The title is self explanatory, i have 5 objects in the scene, 4 capsules and a sphere. When I click on the ball to select it and then click on a container, i would like to destroy the ball, but as it stands, the entire scene is deleted.
Can anyone shed some light on my mistake? Code below:
using UnityEngine;
using System.Collections;
public class selectObject : MonoBehaviour
{
public bool isSelected = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
RaycastHit hitInfo = new RaycastHit ();
bool hit = Physics.Raycast (Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo);
if (Input.GetMouseButtonDown (0) && hit)
{
Debug.Log("Hit " + hitInfo.transform.gameObject.name);
if (hitInfo.transform.gameObject.tag == "red" && hitInfo.transform.gameObject.name == "Ball")
{
isSelected = true;
}
if(isSelected == true)
{
if (hitInfo.transform.gameObject.name == "Capsule")
{
Debug.Log ("I'm here");
Destroy (gameObject);
}
}
}
}
//check if object is selected, if it is, click on container
//you want it to go in, if isSelected == true and the colour tag
//matches the container tag, destroy object and award score
}