Click on specific object to win game and move to next level please help!
Hey everyone I just wondering if someone could point me in the right direction on how to accomplish this. I have 6 triangles in my game. It is a single scene game. They are all tagged with "TriangleP". They also all have Box Collider 2D. I created a script to randomize which triangle is assigned to a moving script (from itween):
public GameObject[] Triangles;
// Use this for initialization
void Start () {
Triangles = GameObject.FindGameObjectsWithTag ("TriangleP");
Triangles [Random.Range (0, Triangles.Length)].AddComponent<MoveSample> ();
}
I also have a java script to detect mouse clicking and it only registers success when it clicks on the moving triangle:
function Update () {
var hit: RaycastHit2D;
if(Input.GetMouseButtonDown(0)){
hit=Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition) , Vector2.zero);
if(hit.collider!=null){
if(hit.collider.GetComponent(MoveSample)!= null && hit.transform.gameObject.tag=="TriangleP"){
Debug.Log("SUCCESS");
}
}
What I want to accomplish is when I only click on the moving triangle (which is randomized), I "Win the level" and move on to the next level (scene). When I click on the wrong triangle, it is "game over" and is directed to a game over scene. Is there anyway to accomplish this? Any help or hint in the right direction would be Greatly Appreciated! Thank you.