Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Delete me!

Discussion in 'Scripting' started by SP-Designs, Nov 7, 2015.

Thread Status:
Not open for further replies.
  1. SP-Designs

    SP-Designs

    Joined:
    Oct 13, 2015
    Posts:
    184
    Hey there! We are almost done with our 2D game but i tried to create a variable that will store a gameobject array and then use it in an if statement inside the OnMouseDown function but it does not work.So we got 2 objects a blue dot and a red dot.I want my script to do this : when you click on the red dot(tagged"Red") you lose and it loads the MainMenu level or if you click on the blue dot(tagged"Blue") you win and it loads the next level.I think an if statement will do but looks like i got something wrong so if you can help me it would be great!Here is my code :

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class OnClick : MonoBehaviour {
    6.  
    7.    private GameObject prefabs;
    8.  
    9.    void OnMouseDown()
    10.    {
    11.      prefabs = GameObject.FindGameObjectsWithTag ("Red");
    12.      if (prefabs = GameObject.FindGameObjectsWithTag ("Red")) {
    13.        Application.LoadLevel("Main Menu");
    14.      }
    15.    }
    16.  
    17. }
    18.  
    Then i get an error that a gameobject cannot be set to a bool value.Please help us finish this game!
     
  2. vintar

    vintar

    Joined:
    Sep 18, 2014
    Posts:
    90
    You probably meant to say if(prefabs != null) or if(prefabs.Length > 1)
     
  3. flonch

    flonch

    Joined:
    Aug 20, 2014
    Posts:
    63
    You should leave the contents of your original post even if you solve it shortly after posting, in case someone else has a similar problem or question in the future.
     
    Ryiah likes this.
  4. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    We can't delete threads which have replies.
     
    Ryiah likes this.
Thread Status:
Not open for further replies.