x


Simon Says tutorial question

Hello!

I am following a tutorial named Simon Says, http://www.youtube.com/watch?v=KSwB0N9Axp4

However I am stuck at 34-ish minutes. I have done everything the person said in the video however mine doesn't do what his does. Could anyone help me out?

(http://wtrns.fr/hdz-yb1f1aujL1c you can download my files here, I used WeTransfer).

EDIT: In the video it shows that I can now press a button, all of them should light up. however in my project it doesn't light up nor can I press on any of the 4 buttons.

Code 1 named 'SimonSays'

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

struct SimonLightPlate
{
    public enum eType
    {
       INVALID_TYPE = -1,
       BLUE,
       GREEN,
       RED,
       YELLOW,
       NUM_TYPES
    }

    public SimonLightPlate( string plateName )
    {
       plate = GameObject.Find (plateName);
    }

    public GameObject plate; //The plate associated with the colors.
}

public class SimonSays : MonoBehaviour 
{

    SimonLightPlate[] lightPlates = new SimonLightPlate[(int)SimonLightPlate.eType.NUM_TYPES];

    enum eState    
    {
       INVALID_STATE = -1,
       THINKING,
       DISPLAY_SEQUENCE,
       WAITING_FOR_USER,
       NUM_STATES
    }

    eState currentState = eState.INVALID_STATE;

    List<int> sequence = new List<int>(100); // hold the sequence
    int sequenceCount = 0; //The counter for which index of the sequence we're currently showing

    List<int> clickedSequence = new List<int>(100); 

    // Use this for initialization
    void Start () 
    {
       lightPlates[(int)SimonLightPlate.eType.BLUE]  = new SimonLightPlate("BluePlane");
       lightPlates[(int)SimonLightPlate.eType.GREEN]     = new SimonLightPlate("GreenPlane");
       lightPlates[(int)SimonLightPlate.eType.YELLOW]    = new SimonLightPlate("YellowPlane");
       lightPlates[(int)SimonLightPlate.eType.RED]   = new SimonLightPlate("RedPlane");


    }

    void OnLeftClickDown(SimonLightPlate.eType color)
    {
       lightPlates[(int)color].plate.renderer.enabled = true;
    }



    // Update is called once per frame
    void Update () 
    {

    }

    void ResetGame()
    {

    }
}

Code 2 named 'ColorPlateClickHandler'

using UnityEngine;
using System.Collections;

public class ColorPlateClickHandler : MonoBehaviour 
{
    void OnMouseOver()
    {
       //Handle left mouse click.
       if (Input.GetMouseButtonDown(0))
       {
         SimonLightPlate.eType colorPlate = SimonLightPlate.eType.INVALID_TYPE;
         if (this.name ==        "BlueClickPlane")
         {
          colorPlate = SimonLightPlate.eType.BLUE;
         }
         else if (this.name ==    "RedClickPlane")
         {
          colorPlate = SimonLightPlate.eType.RED;
         }
         else if (this.name ==    "YellowClickPlane")
         {
          colorPlate = SimonLightPlate.eType.YELLOW;
         }
         else if (this.name ==    "GreenClickPlane")
         {
          colorPlate = SimonLightPlate.eType.GREEN;
         }

         this.SendMessageUpwards("OnLeftClickDown", colorPlate, SendMessageOptions.DontRequireReceiver);  
       }

    }

    void OnMouseUp()
    {
       if (Input.GetMouseButtonUp(0))
       {
         this.SendMessageUpwards("OnLeftClickUp", this.name, SendMessageOptions.DontRequireReceiver);
       }
    }
}
more ▼

asked May 16 '12 at 12:28 PM

Suraci gravatar image

Suraci
46 7 9 10

you need to provide MUCH more info than that. I am all for helping noobs (as I consider myself a noob!), but even I'm not going to watch a video for 35mins to see what is going on.

So, for a better chance at getting some help , try elaborating :

What is the exact problem (not just "mine doesn't do what his does") ?

Where is the script you have written so far?

May 16 '12 at 04:18 PM alucardj

Sorry, I was bit too focused on trying to fix it that I completely forgot about the fact that no-one can just look into my brains and see the problem I got :p.

I have edited my post and hopefully it's a bit more clear now. The problem I got is that the person in the video shows that he can click all the 4 buttons and the light on them will disappear, however when I run my version I can't click on any of the buttons plus I can't really see if they light up or not. (which he'll show around 34-ish minutes.)

May 16 '12 at 04:31 PM Suraci

at a glance I would say first check that your object names match the names you have stated in the ColorPlateClickHandler script. i.e. your yellow plate object is called YellowClickPlane , etc.

You could also check what is being sent to the OnLeftClickDown method by adding this to the ColorPlateClickHandler script :

this.SendMessageUpwards("OnLeftClickDown", colorPlate, SendMessageOptions.DontRequireReceiver);
// ** ADD THIS **
Debug.Log("OnMouseOver-MouseButton(0): colorPlate = " + colorPlate + " . This Object's name is " + this.name);

Check what appears in the console when while playing you mouse over and click on a plate. This should tell you what info is being passed to the SimonSays script.

Also , in your main script , you could add another debug in the SimonSays script to see if the method is actually being called :

void OnLeftClickDown(SimonLightPlate.eType color)
{
   lightPlates[(int)color].plate.renderer.enabled = true;
Debug.Log("SimonSays : Color received = " + color);
}

You could always watch it again and check your script and object setup is the same as the video. True story - I once repeated a tutorial just because I missed a single minus sign. Also now you've done the tutorial , it should be much easier to understand what is going on, and your knowledge should improve on how to use enum, List and SendMessage for yourself.

C# is not my native language, and it is way past my bedtime, so I shall check this question tomorrow to see where you are up to =]

May 16 '12 at 04:57 PM alucardj

just saw your comment. np , it's just easier to help when all the info is ready available. Quick reflection on your comment :

can click all the 4 buttons and the light on them will disappear

don't know how the project / prefabs / materials are set up , but on mouse-click you have :

lightPlates[(int)color].plate.renderer.enabled = true;

to me that makes the material visable After clicking. I shall look later when my brain has recharged, but still try debugging and check all your naming and parenting of objects.

May 16 '12 at 05:09 PM alucardj

Thanks for the quick help, seems the problem lays somewhere at

void OnLeftClickDown(SimonLightPlate.eType color) { lightPlates[(int)color].plate.renderer.enabled = true; Debug.Log("SimonSays : Color received = " + color); }

I have make it true and false but I don't get anything in my log. I am now gonna check all the names I've used and see if that needs to have some judgement. Hopefully it's just a little thing I over looked :/.

PS I have re-done this part 4 times so far ;D. I can probably type it out of my head right now o.0'

May 16 '12 at 05:11 PM Suraci
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

I have uploaded a package with my finished project. I think the most confusing part was the start when the planes are created and the textures are added. All I can suggest is check your plane placement to mine. Make sure that :

the (Red Green Blue Yellow) ClickPlane 's are just above the (RGBY) Plane 's (so they can be clicked on),

and the (RGBY) ClickPlane 's have the Transparent texture,

and the (RGBY) Plane 's have the button ON texture (lit up colour).

and the BasePlane should have the button OFF texture (all the buttons displayed as OFF)

Also when there are 2 colours displayed in a row it is hard to tell, you should add a small delay between each DisplaySequence ( I cannot help there as I don't know how to yield WaitForSeconds(0.2); in C#).

Here is the Package : http://www.alucardj.net16.net/unityanswers/Simon_Says.unitypackage

and a webpublish build : http://www.alucardj.net16.net/unityanswers/SimonSays.html

Definitely try the 3D Buzz tutorial i linked earlier , or any other 3D Buzz tutorial on their website , as they do tutorials in C#. Hope this helps =]

more ▼

answered May 17 '12 at 06:32 PM

alucardj gravatar image

alucardj
13.7k 34 55 86

Will do, and I shall now compare your work with mines, hopefully I can fix my own script and laugh about it later on :P. Thanks again.

May 17 '12 at 06:58 PM Suraci

Hey it has been a while but I got a few questions, I am currently just trying to complete some of the tutorials I've done (making a main menu, score and sound). However I can't get the score list working, any advice how to get this to work?

Jun 07 '12 at 03:33 PM Suraci
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x662
x316

asked: May 16 '12 at 12:28 PM

Seen: 639 times

Last Updated: Jun 07 '12 at 03:33 PM