/// <summary> /// Update this instance. /// </summary> void Update() { m_BounceTimer -= Time.deltaTime; // Randomly bounce around if (m_BounceTimer < 0.0f) { Vector3 jumpVector = Vector3.zero; jumpVector.x = UnityEngine.Random.Range(m_MinJumpVector.x, m_MaxJumpVector.x); jumpVector.y = UnityEngine.Random.Range(m_MinJumpVector.y, m_MaxJumpVector.y); jumpVector.z = UnityEngine.Random.Range(m_MinJumpVector.z, m_MaxJumpVector.z); jumpVector.Normalize(); Vector3 torqueVector = Vector3.zero; torqueVector.x = UnityEngine.Random.Range(m_MinTorqueVector.x, m_MaxTorqueVector.x); torqueVector.y = UnityEngine.Random.Range(m_MinTorqueVector.y, m_MaxTorqueVector.y); torqueVector.z = UnityEngine.Random.Range(m_MinTorqueVector.z, m_MaxTorqueVector.z); torqueVector.Normalize(); m_JellyMesh.AddForce(jumpVector * UnityEngine.Random.Range(m_MinJumpForce, m_MaxJumpForce), m_CentralPointOnly); m_JellyMesh.AddTorque(torqueVector * UnityEngine.Random.Range(m_MinTorqueForce, m_MaxTorqueForce), false); m_BounceTimer = UnityEngine.Random.Range(m_MinBounceTime, m_MaxBounceTime); } m_EyeTimer -= Time.deltaTime; m_QuaternionLerpTimer += Time.deltaTime; if (m_EyeLeft && m_EyeRight) { if (m_EyeTimer < 0.0f) { m_EyeTimer = UnityEngine.Random.Range(2.0f, 3.0f); m_QuaternionLerpTimer = 0.0f; float randomXAngle = UnityEngine.Random.Range(-45, 45); float randomZAngle = UnityEngine.Random.Range(-45, 45); m_StartEyeRotation = m_EyeLeft.transform.localRotation; m_EndEyeRotation = m_EyeInitialRotation * Quaternion.Euler(randomXAngle, 0.0f, randomZAngle); } Quaternion lerpedRotation = Quaternion.Lerp(m_StartEyeRotation, m_EndEyeRotation, Mathf.Clamp01(m_QuaternionLerpTimer * 2)); m_EyeLeft.transform.localRotation = lerpedRotation; m_EyeRight.transform.localRotation = lerpedRotation; } }
private IEnumerator JumpJelly() { while (true) { yield return(new WaitForSeconds(jumpWait)); Vector3 jumpVector = Vector3.up * Random.Range(minJumpPower, maxJumpPower); Vector3 torqueVector = Vector3.zero; torqueVector.x = Random.Range(-1.0f, 1.0f); torqueVector.y = Random.Range(-1.0f, 1.0f); torqueVector.z = Random.Range(-1.0f, 1.0f); torqueVector.Normalize(); torqueVector *= Random.Range(minTorquePower, maxTorquePower); jelly.AddForce(jumpVector, true); jelly.AddTorque(torqueVector, false); jumpWait = Random.Range(2.0f, 4.0f); } }