/// <summary>
    /// 转向方向
    /// </summary>
    /// <param name="dir">1=左 2=右</param>
    public void DirectTo(FaceTo dir)
    {
        //向左
        if (dir == FaceTo.Left)
        {
            if (battleAgent.BaseSprite.FaceTo == dir)
            {
                return;
            }

            battleAgent.BaseSprite.FaceTo = dir;
            Vector3 theScale = transform.localScale;
            theScale.x           = 1;
            transform.localScale = theScale;
        }

        if (dir == FaceTo.Right)
        {
            if (battleAgent.BaseSprite.FaceTo == dir)
            {
                return;
            }

            battleAgent.BaseSprite.FaceTo = dir;
            Vector3 theScale = transform.localScale;
            theScale.x          *= -1;
            transform.localScale = theScale;
        }
    }
Example #2
0
    // Start is called before the first frame update
    void Start()
    {
        if (instance == null)
        {
            instance = this;
        }

        AudioManagerController.instance.StartCoroutine("StartMainSceneBackgroundMusic");

        potionMode     = PotionMode.Fire;
        previousPotion = potionMode;
        aimTo          = AimTo.Right;
        faceTo         = FaceTo.Right;

        health = Mathf.Clamp(health, 0, health);

        rb2d           = GetComponent <Rigidbody2D>();
        animator       = GetComponent <Animator>();
        spriteRenderer = GetComponent <SpriteRenderer>();

        shaderGUItext        = Shader.Find("GUI/Text Shader");
        shaderSpritesDefault = Shader.Find("Sprites/Default"); // or whatever sprite shader is being used
        isAlive = true;
    }
Example #3
0
    /// <summary>
    /// 转向方向
    /// </summary>
    /// <param name="dir">1=左 2=右</param>
    public void DirectTo(FaceTo dir)
    {
        //向左
        if (dir == FaceTo.Left) {

            if (battleAgent.BaseSprite.FaceTo == dir) {
                return;
            }

            battleAgent.BaseSprite.FaceTo = dir;
            Vector3 theScale = transform.localScale;
            theScale.x = 1;
            transform.localScale = theScale;
        }

        if (dir == FaceTo.Right) {
            if (battleAgent.BaseSprite.FaceTo == dir) {
                return;
            }

            battleAgent.BaseSprite.FaceTo = dir;
            Vector3 theScale = transform.localScale;
            theScale.x *= -1;
            transform.localScale = theScale;
        }
    }
Example #4
0
    private void Move(float moveHorizontal) //Control the movement of player
    {
        FlipPlayer();                       //Detect and flip player based on condition
        if (isAiming)
        {
            if (aimTo == AimTo.Right)
            {
                if (moveHorizontal > 0)
                {
                    transform.Translate(Vector3.right * moveHorizontal * moveSpeed * Time.deltaTime);
                    //rb2d.MovePosition(Vector2.right * moveHorizontal * moveSpeed * Time.deltaTime);
                    animator.SetBool("isBackward", false);
                    animator.SetBool("isForward", true);

                    faceTo = FaceTo.Right;
                }
                else if (moveHorizontal < 0)
                {
                    transform.Translate(Vector3.right * moveHorizontal * moveSpeed * Time.deltaTime);
                    animator.SetBool("isForward", false);
                    animator.SetBool("isBackward", true);

                    faceTo = FaceTo.Right;
                }
                else
                {
                    transform.Translate(Vector3.right * moveHorizontal * moveSpeed * Time.deltaTime);
                    animator.SetBool("isForward", false);
                    animator.SetBool("isBackward", false);

                    faceTo = FaceTo.Right;
                }
            }
            else
            {
                if (moveHorizontal > 0)
                {
                    transform.Translate(Vector3.right * moveHorizontal * moveSpeed * Time.deltaTime);
                    animator.SetBool("isForward", false);
                    animator.SetBool("isBackward", true);

                    faceTo = FaceTo.Left;
                }
                else if (moveHorizontal < 0)
                {
                    transform.Translate(Vector3.right * moveHorizontal * moveSpeed * Time.deltaTime);
                    animator.SetBool("isBackward", false);
                    animator.SetBool("isForward", true);

                    faceTo = FaceTo.Left;
                }
                else
                {
                    animator.SetBool("isForward", false);
                    animator.SetBool("isBackward", false);

                    faceTo = FaceTo.Left;
                }
            }
        }
        else
        {
            if (moveHorizontal > 0)
            {
                //rb2d.MovePosition(rb2d.position + new Vector2(moveHorizontal, 0) * moveSpeed * Time.fixedDeltaTime);
                transform.Translate(Vector3.right * moveHorizontal * moveSpeed * Time.deltaTime);
                animator.SetBool("isBackward", false);
                animator.SetBool("isForward", true);

                faceTo = FaceTo.Right;
            }
            else if (moveHorizontal < 0)
            {
                transform.Translate(Vector3.right * moveHorizontal * moveSpeed * Time.deltaTime);
                animator.SetBool("isBackward", false);
                animator.SetBool("isForward", true);

                faceTo = FaceTo.Left;
            }
            else
            {
                animator.SetBool("isForward", false);
                animator.SetBool("isBackward", false);
            }
        }
    }
Example #5
0
    protected virtual void Start()
    {
        this.forceFaceTo = FaceTo.None;
        this.faceTo = FaceTo.None;
        this.autoHit = this.GetComponent<AutoHit>();
        this.spriteRanderer = this.GetComponent<SpriteRenderer>();
        this.anim = this.GetComponent<Animator>();
        this.rightScale = this.transform.localScale;
        this.leftScale = new Vector3(-this.rightScale.x, this.rightScale.y, this.rightScale.z);
        this.health = maxHealth;

        var hitManagers = this.GetComponentsInChildren<HitManager>();
        foreach (var item in hitManagers)
        {
            if (item.tag == "HitColider")
            {
                this.hitManager = item;
                continue;
            }

            if (item.tag == "BackHitColider")
            {
                this.backHitManager = item;
                continue;
            }
        }

        AddItself();
    }
Example #6
0
 public void TurnBack()
 {
     if (this.faceTo == FaceTo.Right)
     {
         this.transform.localScale = this.leftScale;
         this.faceTo = FaceTo.Left;
     }
     else
     {
         this.transform.localScale = this.rightScale;
         this.faceTo = FaceTo.Right;
     }
 }
Example #7
0
    public void MoveToTarget()
    {
        if (this.dead || this.Target == null)
        {
            this.forceFaceTo = FaceTo.None;
            return;
        }

        var targetPosition = this.Target.transform.position;
        var thisPosition = this.transform.position;

        if (thisPosition.x < targetPosition.x)
        {
            this.forceFaceTo = FaceTo.Right;
            this.SetMovePosition(targetPosition - targetRightPositionOffset);

        }
        else
        {
            this.forceFaceTo = FaceTo.Left;
            this.SetMovePosition(targetPosition + targetRightPositionOffset);
        }
    }
Example #8
0
 public void MoveToRight()
 {
     var thisPosition = this.transform.position;
     this.SetMovePosition(thisPosition + new Vector3(playgroundHalfWidth * 2, 0, 0));
     this.forceFaceTo = FaceTo.Right;
 }