예제 #1
0
    // Update is called once per frame
    void Update()
    {
        effect.transform.position = currentPosition;
        currentPosition           = activeCharacter.transform.position;
        if (Time.time >= timeToSwitch && !dead)
        {
            if (Input.GetKeyDown("1"))
            {
                if (activeCharacterIndex != 0)
                {
                    fuelBar.SetActive(true);
                    SwapCharacter(0);
                    ActivateCharacter();
                    Shooting ability = FindObjectOfType <Shooting>();
                    if (ability.sonic)
                    {
                        ability.ResumeSonic();
                    }
                    else
                    {
                        ability.ResumeCooldown();
                    }
                }
                //FindObjectOfType<Fuel>().gameObject.SetActive(true);
                timeToSwitch = Time.time + switchDelay;
            }

            if (Input.GetKeyDown("2"))
            {
                if (activeCharacterIndex != 1)
                {
                    fuelBar.SetActive(false);
                    SwapCharacter(1);
                    ActivateCharacter();
                    Genji ability = FindObjectOfType <Genji>();
                    ability.ResumeCooldown();
                }
                // FindObjectOfType<Fuel>().gameObject.SetActive(false);
                timeToSwitch = Time.time + switchDelay;
            }

            if (Input.GetKeyDown("3"))
            {
                if (activeCharacterIndex != 2)
                {
                    fuelBar.SetActive(false);
                    SwapCharacter(2);
                    ActivateCharacter();
                    Tanya tanya = FindObjectOfType <Tanya>();
                    tanya.chargingJump = false;
                    tanya.jumpCharge   = 0;
                    FindObjectOfType <JumpCharge>().SetHeight(0);
                    FindObjectOfType <PlayerMovementController>().jumpMultiplier = 0;
                    LaunchHook ability1 = FindObjectOfType <LaunchHook>();
                    ability1.ResumeCooldown();
                    ActivateShield ability2 = FindObjectOfType <ActivateShield>();
                    ability2.ResumeCooldown();
                    //FindObjectOfType<Fuel>().gameObject.SetActive(false);
                    timeToSwitch = Time.time + switchDelay;
                }
            }
        }


        activeCharacter.transform.position = currentPosition;


        void ActivateCharacter()
        {
            for (int i = 0; i < characters.Count; i++)
            {
                if (characters[i].name != activeCharacter.name)
                {
                    characters[i].GetComponent <Player>().parent.SetActive(false);
                    characters[i].SetActive(false);
                }
                else
                {
                    characters[i].GetComponent <Player>().parent.SetActive(true);
                    characters[i].SetActive(true);
                }
            }

            for (int i = 0; i < avatars.Count; i++)
            {
                if (i == activeCharacterIndex)
                {
                    avatars[i].SetActive(true);
                    Image image = avatarsSmall[i].GetComponent <Image>();
                    var   color = image.color;
                    color.a     = 1f;
                    image.color = color;
                }
                else
                {
                    avatars[i].SetActive(false);
                    Image image = avatarsSmall[i].GetComponent <Image>();
                    var   color = image.color;
                    color.a     = 0.3f;
                    image.color = color;
                }
            }
        }
    }