Exemplo n.º 1
0
    IEnumerator MoveToHeightLevelRoutine(GameEnum.HeightLevel heightLevel)
    {
        float startHeight  = this.transform.position.y;
        float targetHeight = (heightLevel == GameEnum.HeightLevel.LOWER) ? DataManager.HEIGHT_LEVEL_LOWER : DataManager.HEIGHT_LEVEL_UPPER;
        float timer        = 0.0f;
        float duration     = 2.0f;
        float parametric   = 0.0f;
        float rotationX    = 0.0f;
        float maxRotationX = (heightLevel == GameEnum.HeightLevel.LOWER) ? 20f : -20f;

        while (timer < duration)
        {
            yield return(new WaitForEndOfFrame());

            parametric = (TrigLookup.Sin(((timer / duration) * Mathf.PI) - Mathf.PI / 2.0f) * 0.5f) + 0.5f;
            rotationX  = TrigLookup.Sin((timer / duration) * Mathf.PI);
            //Debug.Log (parametric);

            this.transform.position            = new Vector3(this.transform.position.x, Mathf.Lerp(startHeight, targetHeight, parametric), this.transform.position.z);
            this.model.transform.localRotation = Quaternion.Lerp(this.model.transform.localRotation,
                                                                 Quaternion.Euler(rotationX * maxRotationX, this.model.transform.localRotation.y, this.model.transform.localRotation.z),
                                                                 parametric);

            timer += Time.deltaTime;
        }

        this.transform.position            = new Vector3(this.transform.position.x, targetHeight, this.transform.position.z);
        this.model.transform.localRotation = Quaternion.Euler(0, this.model.transform.localRotation.y, this.model.transform.localRotation.z);
        this.heightLevel    = heightLevel;
        this.isMovingHeight = false;

        /*if (this.heightLevel == GameEnum.HeightLevel.LOWER)
         *      this.transform.position = new Vector3 (this.transform.position.x, Mathf.Lerp (this.transform.position.y, this.startPos.y, Time.deltaTime * 5), this.transform.position.z);
         * else if (this.heightLevel == GameEnum.HeightLevel.UPPER)
         *      this.transform.position = new Vector3 (this.transform.position.x, Mathf.Lerp (this.transform.position.y, this.startPos.y + 10, Time.deltaTime * 5), this.transform.position.z);*/
    }
Exemplo n.º 2
0
 public void SetHeightLevel(GameEnum.HeightLevel heightLevel)
 {
     if (this.heightLevel != heightLevel && !this.isMovingHeight)
     {
         if (heightLevel == GameEnum.HeightLevel.LOWER)
         {
             RaycastHit hit;
             if (Physics.Raycast(this.transform.position, Vector3.down, out hit, 10.0f, LayerMask.GetMask(new string[] { "EnvironmentCollider" })))
             {
                 Debug.Log(string.Format("cannot lower: {0}", hit.transform.name));
             }
             else
             {
                 this.isMovingHeight = true;
                 StartCoroutine("MoveToHeightLevelRoutine", heightLevel);
             }
         }
         else
         {
             this.isMovingHeight = true;
             StartCoroutine("MoveToHeightLevelRoutine", heightLevel);
         }
     }
 }