示例#1
0
    private void Update()
    {
        moving = pCont.GetSpeed();
        //backing = pCont.GetJoyVer();
        jumped = pCont.GetAir();


        if (underAttack && attackZoom)
        {
            if (dstFromTarget < aZoom)
            {
                currentDstFromTarget += .1f;
                dstFromTarget        += .1f;
            }
            if (pitch < 40f)
            {
                pitch += .7f;
            }
        }
        else
        {
            if (dstFromTarget > 3.3f)
            {
                currentDstFromTarget -= .1f;
                dstFromTarget        -= .1f;
            }
            if (pitch > 3f)
            {
                pitch -= .7f;
            }
            //currentDstFromTarget = 3.26f;
            //dstFromTarget = 3.26f;
        }

        if (moving && !underAttack)
        {
            // Debug.Log(pitch);
            if (pitch < defPitch)
            {
                if (pitch + 3f < defPitch)
                {
                    pitch += 3f;
                }
                else
                {
                    pitch = defPitch;
                }
            }
            if (pitch > defPitch)
            {
                if (pitch - 3f > defPitch)
                {
                    pitch -= 3f;
                }
                else
                {
                    pitch = defPitch;
                }
            }
        }


        //currentDstFromTarget = Mathf.Clamp(currentDstFromTarget, 1.4f, dstFromTarget);
        // RaycastHit hit;
        RaycastHit hitDown;

        if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.down), out hitDown, 1.5f))
        {
            // Debug.Log("hitDown " + hitDown.transform.name);

            // Debug.Log("++");
            pitch += 0.7f;
        }
        if (!Physics.Raycast(transform.position, transform.TransformDirection(Vector3.down), out hitDown, 1.8f) && currentPitch >= 4 && currentPitch <= 30 && !underAttack)
        {
            //Debug.Log("hitDown " + hitDown.transform.name);
            //Debug.Log("--");
            pitch -= 0.7f;
        }

        /*
         *  if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, currentDstFromTarget))
         * {
         *  //Debug.Log(hit.transform.name);
         *
         *  if (hit.transform.name != "unicorn" && hit.transform.name != "WaterBasicDaytime")
         *  {
         *      //currentDstFromTarget -= 0.1f;
         *     // Debug.Log("hit " + hit.transform.name);
         *  }
         *  else
         *  {
         *      if (Physics.Raycast(nextPos, transform.TransformDirection(Vector3.forward), out hit, currentDstFromTarget + 0.2f))
         *      {
         *          if (hit.transform.name == "unicorn")
         *          {
         *             // Debug.Log("hit " + hit.transform.name);
         *             // currentDstFromTarget += 0.1f;
         *          }
         *      }
         *  }
         * }*/
    }