Exemplo n.º 1
0
    private void SetTrap()
    {
        if (ghostTrap != null)
        {
            //Check if trap is on correct surface
            bool validLocation;
            CheckMultipleBases  bases = ghostTrap.GetComponentInChildren <CheckMultipleBases>();
            CheckValidLocations check = ghostTrap.GetComponentInChildren <CheckValidLocations>();


            if (bases != null)
            {
                validLocation = bases.Valid;
            }
            else if (check != null)
            {
                validLocation = check.Valid;
            }
            else
            {
                validLocation = true;
                Debug.Log("Warning: Trap not set up correctly; valid location is always true.");
            }

            //CheckNearby() also checks the collider provided for the "safe zone" around the trap
            if (GetGridPosition() != null && CheckNearby() && validLocation)
            {
                Vector3 position = GetGridPosition().Value;
                if (ghostTrap != null && CheckFloor(position.y))
                {
                    audioSource.PlayOneShot(trapPlacementGood);
                    trap.InstantiateTrap(position, ghostTrap.transform.rotation);
                    if (check != null)
                    {
                        check.Placed = true;
                    }
                    //if (bases != null) bases.Placed = true;
                    ClearButton();
                    trap = null;
                    foreach (SpriteRenderer sr in placementSquares)
                    {
                        sr.enabled = false;
                    }
                    placementSquares = null;
                    DestroyGhost();

                    SetSelectedButton();
                }
                else
                {
                    audioSource.PlayOneShot(trapPlacementBad);
                }
            }
            else
            {
                audioSource.PlayOneShot(trapPlacementBad);
            }
        }
    }
Exemplo n.º 2
0
    private void MoveGhost()
    {
        if (ghostTrap != null)
        {
            UpdateRotationInput();
            FinalizeRotationInput();
            bool validLocation;
            CheckMultipleBases  bases = ghostTrap.GetComponentInChildren <CheckMultipleBases>();
            CheckValidLocations check = ghostTrap.GetComponentInChildren <CheckValidLocations>();

            if (bases != null)
            {
                validLocation = bases.Valid;
            }
            else if (check != null)
            {
                validLocation = check.Valid;
            }
            else
            {
                validLocation = true;
                Debug.Log("Warning: Trap not set up correctly; valid location is always true.");
            }

            if (validLocation && CheckNearby() && GetGridPosition() != null && placementSquares.Length == 2)
            {
                if (placementSquares[0] != null)
                {
                    placementSquares[0].enabled = false;
                }
                if (placementSquares[1] != null)
                {
                    placementSquares[1].enabled = true;
                }
            }
            else if (placementSquares.Length == 2)
            {
                if (placementSquares[0] != null)
                {
                    placementSquares[0].enabled = true;
                }
                if (placementSquares[1] != null)
                {
                    placementSquares[1].enabled = false;
                }
            }
            if (GetGridPosition() != null)
            {
                //Rotate trap based on side of tower
                switch (cam.GetComponent <CameraTwoRotator>().GetState())
                {
                case 1:
                    ghostTrap.transform.eulerAngles = new Vector3(ghostTrap.transform.eulerAngles.x, 0, ghostTrap.transform.eulerAngles.z);
                    break;

                case 2:
                    ghostTrap.transform.eulerAngles = new Vector3(ghostTrap.transform.eulerAngles.x, 270, ghostTrap.transform.eulerAngles.z);
                    break;

                case 3:
                    ghostTrap.transform.eulerAngles = new Vector3(ghostTrap.transform.eulerAngles.x, 180, ghostTrap.transform.eulerAngles.z);
                    break;

                case 4:
                    ghostTrap.transform.eulerAngles = new Vector3(ghostTrap.transform.eulerAngles.x, 90, ghostTrap.transform.eulerAngles.z);
                    break;
                }
                Vector3 position = GetGridPosition().Value;
                ghostTrap.transform.position = position;

                //Cancel the trap
                if ((Input.GetMouseButton(1) || Input.GetButton("Cancel_Joy_2")) && !pause.GameIsPaused)
                {
                    DestroyGhost();
                    placementSquares = null;
                    SetSelectedButton();
                }
            }
        }
    }