Exemple #1
0
 // Use this for initialization
 void Start()
 {
     attack          = attackDirection.none;
     currentMovement = 0;
     localScale      = gameObject.transform.localScale;
     localPosition   = gameObject.transform.localPosition;
 }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        if (GameVariables.GameMode == GameVariables.GameModes.Hero &&
            GameVariables.PlayerWeapon == GameVariables.PlayerWeapons.Close)
        {
            //weapon appears after weapon change
            if (gameObject.transform.localScale != localScale)
            {
                gameObject.transform.localScale = localScale;
                gameObject.GetComponent <BoxCollider>().enabled = true;
            }

            if (attack != attackDirection.none)
            {
                if (attack == attackDirection.down)
                {
                    if (MusicSource.isPlaying == false)
                    {
                        MusicSource.PlayOneShot(MusicClipSwing);
                    }
                    if (currentMovement > -maxMovement)
                    {
                        currentMovement += attackSpeed * Time.deltaTime;
                        //gameObject.transform.Translate(-1 * gameObject.GetComponentInParent<Transform>().right * attackSpeed * Time.deltaTime, Space.World);
                        gameObject.transform.Translate(-1 * gameObject.transform.up * attackSpeed * Time.deltaTime, Space.World);
                    }
                    else
                    {
                        attack          = attackDirection.up;
                        attackSpeed    *= -1;//change rotation direction
                        currentMovement = 0;
                    }
                }
                else if (attack == attackDirection.up)
                {
                    if (currentMovement < maxMovement)
                    {
                        currentMovement += attackSpeed * Time.deltaTime;
                        //gameObject.transform.Translate(-1 * gameObject.GetComponentInParent<Transform>().right * attackSpeed * Time.deltaTime, Space.World);
                        gameObject.transform.Translate(-1 * gameObject.transform.up * attackSpeed * Time.deltaTime, Space.World);
                    }
                    else
                    {
                        attack          = attackDirection.none;
                        attackSpeed    *= -1;//change rotation direction
                        currentMovement = 0;
                    }
                }
            }

            if (Input.GetMouseButtonDown(0) && attack == attackDirection.none)
            {
                attack = attackDirection.down;
            }
        }

        //weapon disappear after weapon change
        if (GameVariables.PlayerWeapon != GameVariables.PlayerWeapons.Close &&
            gameObject.transform.localScale == localScale)
        {
            //gameObject.GetComponent<MeshRenderer>().
            gameObject.GetComponent <BoxCollider>().enabled = false;
            gameObject.transform.localScale    = new Vector3(0, 0, 0);
            gameObject.transform.localPosition = localPosition;
        }
    }
Exemple #3
0
    // Update is called once per frame
    void Update()
    {
        if (GameVariables.GameMode == GameVariables.GameModes.Hero &&
            GameVariables.PlayerWeapon == GameVariables.PlayerWeapons.Close)
        {
            //weapon appears after weapon change
            if (gameObject.transform.localScale != localScale)
            {
                gameObject.transform.localScale = localScale;
            }

            if (attack != attackDirection.none)
            {
                float angle = attackSpeed * Time.deltaTime;
                currentRotation += angle;
                if (attack == attackDirection.down)
                {
                    if (MusicSource.isPlaying == false)
                    {
                        MusicSource.PlayOneShot(MusicClipSwing);
                    }
                    if (currentRotation > -maxRotation)
                    {
                        gameObject.transform.Rotate(transform.forward * angle, Space.World);
                    }
                    else
                    {
                        attack          = attackDirection.up;
                        attackSpeed    *= -1;//change rotation direction
                        currentRotation = 0;
                    }
                }
                else if (attack == attackDirection.up)
                {
                    if (currentRotation < maxRotation)
                    {
                        gameObject.transform.Rotate(transform.forward * angle, Space.World);
                    }
                    else
                    {
                        attack          = attackDirection.none;
                        attackSpeed    *= -1;//change rotation direction
                        currentRotation = 0;
                    }
                }
            }

            if (Input.GetMouseButtonDown(0) && attack == attackDirection.none)
            {
                attack = attackDirection.down;
            }
        }

        //weapon disappear after weapon change
        if (GameVariables.PlayerWeapon != GameVariables.PlayerWeapons.Close &&
            gameObject.transform.localScale == localScale)
        {
            //gameObject.GetComponent<MeshRenderer>().
            gameObject.transform.localScale = new Vector3(0, 0, 0);
        }
    }
Exemple #4
0
 // Use this for initialization
 void Start()
 {
     attack          = attackDirection.none;
     currentRotation = 0;
     localScale      = gameObject.transform.localScale;
 }