示例#1
0
    private void switchCharacter(int newCharacter)
    {
        //Temp player switch
        for (int i = 0; i < currentCharacters.Count; i++)
        {
            this.currentCharacters[i].active = false;
        }

        int newActivePlayer = newCharacter;

        CameraController      cam     = gameObject.GetComponentInChildren <CameraController>();
        EndOfAnimationCalback calback = delegate() { currentCharacters[newActivePlayer].active = true; };

        cam.newTarget(currentCharacters[newActivePlayer].transform, calback);
    }
示例#2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (target == null)
        {
            return;
        }

        float smothness = 2.0f;

        if (!focusAnimationOnNewTarget)
        {
            smothness = 1.0f;
        }

        //Get the direction but only from the x,y position
        Vector3 direction = (target.position - transform.position);

        direction.z = 0;
        direction   = direction.normalized;

        float   distance = ((Vector2)(target.position - transform.position)).magnitude;
        Vector3 newPos   = Vector3.Lerp(transform.position, target.position, smothness * Time.deltaTime);

        if (distance >= maxDistance && !focusAnimationOnNewTarget)
        {
            //max distance
            newPos = target.position - (direction * maxDistance);
        }
        else if (distance <= maxDistance && focusAnimationOnNewTarget)
        {
            focusAnimationOnNewTarget = false;
            endOfAnimationCallback();
            endOfAnimationCallback = null;
        }
        transform.position = new Vector3(newPos.x, newPos.y, transform.position.z);
    }
示例#3
0
 public void newTarget(Transform newTarget, EndOfAnimationCalback callback)
 {
     focusAnimationOnNewTarget = true;
     target = newTarget;
     endOfAnimationCallback = callback;
 }