Search Unity

Trying to make a cookie clicker style menu for buying upgrades as an example

Discussion in 'Getting Started' started by Sylvir, Mar 23, 2015.

  1. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    i have been trying to work out the best way to set this up. I have 3 things that i would like to be able to click on. then when you click on each one id like a new window, or a new pop up to come up and have a list of options that you can select.

    right now i have tried this code, but it is saying there are errors, and i am not quiet sure where i am missing the errors at.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class regionmenutest : MonoBehaviour
    5. {
    6.  
    7.     var plain : GameObject ;
    8.     var spawn_possition;
    9.    
    10.    
    11.     function Start ()
    12.     {
    13.         plain.GameObject.SetActive = false;
    14.         spawn_possition = Vector3 (0, 0, 0);
    15.     }
    16.    
    17.     function Update ()
    18.     {
    19.        
    20.     }
    21.    
    22.     function OnMouseDown ()
    23.     {
    24.         plain.GameObject.SetActicve = true;
    25.     }
    26.  
    27. }
    in my head i was thinking if i assigned the plain that was turned up to the game object in this code i could make it appear when something is clicked. not sure if i did this correctly though, or if there is a better way to do this. any thoughts would be awesome, thanks!

    just looking for what the best way to set something like this up in unity would be. another thought was possibly having each one open a new scene and just building the buttons and upgrades etc. into each new scene and making a back button that sent the user back to my main scene of the game.
     
  2. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,141
    Most likely the typo of "SetActive" in OnMouseDown.
     
  3. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    oh jeeze.. yeah good catch Ryjah! thanks, feel pretty lame missing some of these easy fixes, but thats all part of learning, thanks for the help!
     
  4. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    hmm, i fixed that and i am still getting a couple errors..

    here is the code now

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class regionmenutest : MonoBehaviour
    5. {
    6.  
    7.     var plain : GameObject;
    8.     var spawn_possition;
    9.    
    10.    
    11.     function Start ()
    12.     {
    13.         plain.GameObject.SetActive = false;
    14.         spawn_possition = Vector3 (0, 0, 0);
    15.     }
    16.    
    17.     function Update ()
    18.     {
    19.        
    20.     }
    21.    
    22.     function OnMouseDown ()
    23.     {
    24.         plain.GameObject.SetActive = true;
    25.     }
    26.  
    27. }
     
  5. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    line 7 says it has 2 errors on it.
     
  6. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,208
    You have to declare what the type is, there isn't a way for the compiler to infer the type in a straight declaration. Plus, you're mixing unityscript with csharp syntax.

    instead of var, use the type like this:

    public GameObject plain;
    public Vector3 spawn_possition; // misspelled

    plus the following lines need to be modified:

    spawn_possition = new Vector3(0, 0, 0);

    and

    plain.GameObject.SetActive(true);

    Plus, this is pretty unsafe. What if someone didn't assign the plain object? You should check:

    if (plain != null) plain.GameObject.SetActive(true);

    Before you get much farther, I recommend learning a bit of C#:

    http://www.microsoftvirtualacademy.com/training-courses/c-fundamentals-for-absolute-beginners
     
  7. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    thanks, sorry i was mixing those up.

    yeah, i went through some classes for them, i am going to try to learn some more now. i did a basics course through that java and some others. thought i had it straight, but i guess not. thanks for the help. ill concentrate on just c # right now until i feel like i have that down solid.