-2
using UnityEngine;
using System.Collections;

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];

   // 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.RED] = new SimonLightPlate("RedPlane");
     lightPlates[(int)SimonLightPlate.eType.YELLOW] = new SimonLightPlate("YellowPlane");
   }

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

   }
}
  • What does the (int) do? What does this line of code do:
  • SimonLightPlate[] lightPlates = new SimonLightPlate[(int)SimonLightPlate.eType.NUM_TYPES];? What does this do: lightPlates[(int)SimonLightPlate.eType.BLUE] = new SimonLightPlate("BluePlane");?
  • What would public GameObject plate; do as well?
CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • You really need to read some of the Unity documentation. You're asking questions, of which some are basic programming knowledge. It may be worth investing in a book, or working through the Unity3D video tutorials, before going further. No disrespect intended. Merely an observation. – laminatefish Feb 18 '15 at 15:39

1 Answers1

0
  1. The (int) is being used to cast the enum type to its numerical representation
  2. that line is initialising a new lightplate at lightPlates[0] (most likely assuming that the enum increments by 1 by default)
  3. the gameobject stores a reference to the plate (probably a 2D plane or prefab), using this you can do all kinds of things with the GameObject such as move it around the scene.

It looks like when the game begins the code is loading up 4 different types of plate gameobjects (these could be prefabs/models among other things). It is locating them via Gameobject.Find("object name"). If you go though the inspector in unity you can probably locate items that are named for the respective plate.

As a sidenote you should look at posting questions related to Game Development here in the future

Community
  • 1
  • 1
Matthew Pigram
  • 1,400
  • 3
  • 25
  • 65