コード例 #1
0
    private void SwapSprites()
    {
        SwitchBehavior s = GetSwitchBehavior();

        s.sSwitch        = loopSwitch;
        s.sSwitchPressed = loopSwitchPressed;
        s.GetComponent <SpriteRenderer>().sprite      = s.isPressed ? loopSwitchPressed : loopSwitch;
        s.door.GetComponent <SpriteRenderer>().sprite = doorLooping;
    }
コード例 #2
0
    void Update()
    {
        if (FindObjectOfType <PauseMenu>().paused)
        {
            return;
        }

        //Reference to playerHusk location
        Vector2 playerLocation = playerHusk.transform.position;

        gameOver = playerHealth.GetGameOver();

        if (gameOver) //Don't do behavior
        {
            showBothTeams();
            followCamera.Follow = playerHusk.transform;
        }
        else //Play the game
        {
            if (FindObjectOfType <BasicMovement>() == null)
            {
                ControlCheck = false;
            }
            else
            {
                ControlCheck = true;
            }

            //if wavestart ==true and basicmovement script is not found
            if (newWave == true && FindObjectOfType <BasicMovement>() == null)
            {
                Debug.Log("BasicMovement not found on waveStart");
                Debug.Log("Camera moving to playerHusk");

                //set Camera to follow the husk body so you can click on it
                followCamera.Follow = playerHusk.transform;

                newWave = false;
            }

            // If right mouse button is clicked
            if (Input.GetMouseButtonDown(1))
            {
                // Perform a raycast to see what we clicked
                Ray          ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit2D hitInfo;

                hitInfo = Physics2D.GetRayIntersection(ray);

                // If we actually clicked on something
                if (hitInfo.collider != null)
                {
                    //reference for hit object
                    SBehavior = hitInfo.collider.GetComponent <SwitchBehavior>(); //Checks if is switchable

                    // If the hit object is switchable
                    if (SBehavior != null)
                    {
                        //prep: set player object tag to player inactive
                        Debug.Log("Set player husk to inactive");

                        //Prep: set husk tag to inactive
                        playerHusk.gameObject.tag = "Player Inactive";

                        //reference SBehavior to change the objects behavior to 3 (inactive)
                        playerHusk.GetComponent <SwitchBehavior>().setBehavior(3);

                        //Check that you correctly set behavior
                        Debug.Log("Current Behavior: " + SBehavior.GetComponent <SwitchBehavior>().getBehavior());

                        //If current is player
                        if (SBehavior.GetComponent <SwitchBehavior>().getBehavior() == 3)
                        {
                            //currentBehavior = 3 //(player inactive)
                            Debug.Log("'this' -> means the player husk!");

                            Debug.Log("Running Switch_bodies");

                            //currentBehavior = 2 //(player active)
                            playerHusk.GetComponent <SwitchBehavior>().setBehavior(2);

                            switchBodies(hitInfo.collider.gameObject); //here
                        }

                        //If current is enemy
                        if (SBehavior.GetComponent <SwitchBehavior>().getBehavior() == 1)
                        {
                            //currentBehavior = 1 //(enemy)
                            Debug.Log("'this' -> means the enemy!");

                            SBehavior.GetComponent <SwitchBehavior>().setBehavior(2);
                            Debug.Log("New Behavior: " + SBehavior.GetComponent <SwitchBehavior>().getBehavior());

                            Debug.Log("Running Switch_bodies");
                            switchBodies(hitInfo.collider.gameObject);
                        }
                    }
                }
            }
            if (Input.GetKeyDown(KeyCode.B))
            {
                showBlueTeam();
            }
            if (Input.GetKeyDown(KeyCode.R))
            {
                showRedTeam();
            }
            if (Input.GetKeyDown(KeyCode.G))
            {
                showBothTeams();
            }
        }
    }