Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        Vector3 move = new Vector3();

        Vector3 toPlayer = player.transform.position - transform.position;
        float   dx       = toPlayer.x;

        //Debug.Log(dx);
        if (Mathf.Abs(dx) > MIN_DISTANCE)
        {
            move = Vector3.Normalize(new Vector3(dx, 0.0f)) * speed;
        }

        transform.position += move;

        if (move.x > 0.0f)
        {
            if (direction == GlobalConsts.Orientation.LEFT)
            {
                sword.SwitchSide();
            }
            direction = GlobalConsts.Orientation.RIGHT;
        }
        else if (move.x < 0.0f)
        {
            if (direction == GlobalConsts.Orientation.RIGHT)
            {
                sword.SwitchSide();
            }
            direction = GlobalConsts.Orientation.LEFT;
        }
    }
Exemple #2
0
 void Start()
 {
     orientation = GlobalConsts.Orientation.RIGHT;
     sword.SetSide(GlobalConsts.Orientation.RIGHT);
     rb = GetComponent <Rigidbody> ();
     setSwordActive(false);
     playerAudio = gameObject.GetComponent <PlayerAudio>();
 }
Exemple #3
0
 // Use this for initialization
 void Start()
 {
     transform = this.gameObject.GetComponent <Transform>();
     player    = GameObject.FindGameObjectWithTag("Player").GetComponent <Transform>();
     direction = GlobalConsts.Orientation.RIGHT;
     //sword = this.gameObject.GetComponentInChildren<Sword>();
     //sword.SetSide(GlobalConsts.Orientation.RIGHT);
 }
Exemple #4
0
    private void FixedUpdate()
    {
        // Get horizontal movement
        float moveHorizontal;
        float inputHorizontal = Input.GetAxis("Horizontal");

        if (inputHorizontal > 0)
        {
            moveHorizontal = speed;
        }
        else if (inputHorizontal < 0)
        {
            moveHorizontal = -speed;
        }
        else
        {
            moveHorizontal = 0;
        }

        if (moveHorizontal != 0)
        {
            moveDirection.x = moveHorizontal;
        }
        else
        {
            moveDirection.x = 0;
        }

        // Check if the player jumped
        if (Input.GetButton("Jump") && !hasJumped)
        {
            moveDirection.y = jumpSpeed;
            hasJumped       = true;
            playerAudio.PlayJump();
        }
        else
        {
            moveDirection.y = rb.velocity.y;
        }

        // Sword Orientation
        if (moveHorizontal > 0)
        {
            if (orientation == GlobalConsts.Orientation.LEFT)
            {
                sword.SwitchSide();
                float currentX = sideIndicator.transform.localPosition.x;
                sideIndicator.transform.localPosition = new Vector3(-currentX, 0.0f);
            }
            orientation = GlobalConsts.Orientation.RIGHT;
        }
        else if (moveHorizontal < 0)
        {
            if (orientation == GlobalConsts.Orientation.RIGHT)
            {
                sword.SwitchSide();
                float currentX = sideIndicator.transform.localPosition.x;
                sideIndicator.transform.localPosition = new Vector3(-currentX, 0.0f);
            }
            orientation = GlobalConsts.Orientation.LEFT;
        }

        if (!isWeaponOut && Input.GetKeyDown(KeyCode.DownArrow))
        {
            isWeaponOut = true;
            setSwordActive(true);
            swordAudio.PlayClip();
        }
        else if (isWeaponOut)
        {
            weaponTimer++;
            if (weaponTimer >= weaponCooldown)
            {
                weaponTimer = 0;
                isWeaponOut = false;
                setSwordActive(false);
            }
        }
        rb.velocity = moveDirection;
    }
Exemple #5
0
 public void SetSide(GlobalConsts.Orientation o)
 {
     transform.localPosition = new Vector3((int)o * offset, 0.0f);
     //Debug.Log("Sword Pos for " + gameObject.transform.parent.name + ": " + transform.localPosition);
 }