Exemple #1
0
 void Awake()
 {
     nite = FindObjectOfType(typeof(NiteOpenNet)) as NiteOpenNet;
     selectShape = FindObjectOfType(typeof(SelectShape)) as SelectShape;
     userGui = FindObjectOfType(typeof(UserGuiDeformatory)) as UserGuiDeformatory;
     bouncer = FindObjectOfType(typeof(Bouncer)) as Bouncer;
     ballAnimator = FindObjectOfType(typeof(BallAnimator)) as BallAnimator;
 }
    private void AnimateBall()
    {
        BallAnimator.enabled = true;

        Vector2 direction = MathUtils.CalculateDirection(transform.position, Target.Value);

        if (direction.x == 0 && direction.y < 0)
        {
            //SOUTH DIRECTION
            BallAnimator.SetBool("reverse", false);
        }
        else if (direction.x == 0 && direction.y > 0)
        {
            //NORTH DIRECTION
            BallAnimator.SetBool("reverse", true);
        }
        else if (direction.x < 0 && direction.y == 0)
        {
            //WEST DIRECTION
            BallAnimator.SetBool("reverse", true);
        }
        else if (direction.x > 0 && direction.y == 0)
        {
            //EAST DIRECTION
            BallAnimator.SetBool("reverse", true);
        }
        else if (direction.x > 0 && direction.y > 0)
        {
            //NORTH EAST DIRECTION
            BallAnimator.SetBool("reverse", true);
        }
        else if (direction.x < 0 && direction.y < 0)
        {
            //SOUTH WEST DIRECTION
            BallAnimator.SetBool("reverse", true);
        }
        else if (direction.x < 0 && direction.y > 0)
        {
            //NORTH WEST DIRECTION
            BallAnimator.SetBool("reverse", true);
        }
        else if (direction.x > 0 && direction.y < 0)
        {
            //SOUTH EAST DIRECTION
            BallAnimator.SetBool("reverse", true);
        }

        if (direction.x != 0)
        {
            float angle = MathUtils.CalculateDirectionAngle(direction);
            this.transform.rotation = Quaternion.AngleAxis(angle - 90, Vector3.forward);
        }
    }