//Coroutime to make Gregg walk off-camera public IEnumerator greggDisappearHelper() { _bubbleState = BubbleState.APPEARING; yield return(new WaitForSeconds(4)); _bubbleState = BubbleState.DISAPPEARING; yield return(new WaitForSeconds(3)); _greggState = GreggState.DISAPPEARING; }
//Coroutine to make Gregg walk into view public IEnumerator greggAppearHelper() { if (!_appeared) { yield return(new WaitForSeconds(3)); transform.position = new Vector3(Mathf.Sin(_START_POSITION * Mathf.Deg2Rad) * _RADIUS, _GREGG_Y, Mathf.Cos(_START_POSITION * Mathf.Deg2Rad) * _RADIUS); inGregg = true; _appeared = true; _greggState = GreggState.APPEARING; } }
// Update is called once per frame void Update() { Quaternion q; float angleFromViewpoint; switch (_greggState) { case GreggState.APPEARING: // Gregg will appear behind the player, then walk in an arc to them Vector3 left = Vector3.Cross(Camera.main.transform.position - transform.position, -Vector3.up); transform.RotateAround(Camera.main.transform.position, Vector3.up, -60 * Time.deltaTime); transform.LookAt(left); q = new Quaternion(0, transform.rotation[1], 0, transform.rotation[3]); transform.rotation = Quaternion.Slerp(transform.rotation, q, 360); angleFromViewpoint = Vector3.Angle(RemoveY(Camera.main.transform.forward), RemoveY(transform.position)); if (Mathf.Floor(angleFromViewpoint) == 0) { transform.LookAt(Camera.main.transform); q = new Quaternion(0, transform.rotation[1], 0, transform.rotation[3]); transform.rotation = Quaternion.Slerp(transform.rotation, q, 360); _greggState = GreggState.OFF; } break; case GreggState.DISAPPEARING: // Gregg will appear move in an arc around the player until he's out of sight, then disappear Vector3 right = Vector3.Cross(Camera.main.transform.position - transform.position, Vector3.up); transform.RotateAround(Camera.main.transform.position, Vector3.up, 60 * Time.deltaTime); transform.LookAt(right); q = new Quaternion(0, transform.rotation[1], 0, transform.rotation[3]); transform.rotation = Quaternion.Slerp(transform.rotation, q, 360); angleFromViewpoint = Vector3.Angle(RemoveY(Camera.main.transform.forward), RemoveY(transform.position)); if (Mathf.Floor(angleFromViewpoint) >= 150) { _greggState = GreggState.OFF; gameObject.transform.position += new Vector3(0f, -4f, 0f); } break; default: ; break; } switch (_bubbleState) { case BubbleState.APPEARING: //bubble fades in _bubbleRndr.material.color = Color.Lerp(_bubbleRndr.material.color, _bubbleColor, _TIME_TO_FADE * Time.deltaTime); proText.color = Color.Lerp(proText.color, _textColor, _TIME_TO_FADE * Time.deltaTime); break; case BubbleState.DISAPPEARING: //bubble fades out _bubbleRndr.material.color = Color.Lerp(_bubbleRndr.material.color, _bubbleAlpha, _TIME_TO_FADE * Time.deltaTime); proText.color = Color.Lerp(proText.color, _textAlpha, _TIME_TO_FADE * Time.deltaTime); break; default: ; break; } }
//Used to reset gregg when the scene is reset public void resetGregg() { _appeared = false; _greggState = GreggState.OFF; transform.position = new Vector3(0f, -500f, 0f); }