コード例 #1
0
    private void OnMouseEnter()
    {
        // We only interact with the grid/cells if the menu is closed
        if (!CL_GameManager.isMenuOpen)
        {
            cellHoverState = CellHoverState.HOVER;
            if (cellState == CellState.ALIVE)
            {
                this.gameObject.GetComponent <SpriteRenderer>().color = spriteColorAliveHover;
            }
            else
            {
                this.gameObject.GetComponent <SpriteRenderer>().color = spriteColorDeadHover;
            }

            // If mouse slide over the cell while being held down, we still update the state of the cell
            if (Input.GetMouseButton(0))
            {
                if (cellState == CellState.ALIVE)
                {
                    cellState = CellState.DEAD;
                }
                else
                {
                    cellState = CellState.ALIVE;
                }
            }
        }
    }
コード例 #2
0
 private void OnMouseExit()
 {
     cellHoverState = CellHoverState.IDLE;
     if (cellState == CellState.ALIVE)
     {
         this.gameObject.GetComponent <SpriteRenderer>().color = spriteColorAlive;
     }
     else
     {
         this.gameObject.GetComponent <SpriteRenderer>().color = spriteColorDead;
     }
 }
コード例 #3
0
    private void Start()
    {
        // Find the 'Grid' reference in the hierarchy
        grid = GameObject.Find("Grid").GetComponent <CL_Grid>();

        // States initialization
        cellState      = CellState.DEAD;
        cellHoverState = CellHoverState.IDLE;

        // Grid sprite color initialization
        this.gameObject.GetComponent <SpriteRenderer>().color = spriteColorDead;

        // Neighbours list initialization
        liveNeighbours = new List <CL_Cell>();
    }