using System.Collections; using System.Collections.Generic; using UnityEngine; public class SmileySpawner : MonoBehaviour { public GameObject HitEffectOn; public GameObject HitEffectOff; public Material SmileyMat; private MeshRenderer mr; private GameObject smiley; private GameObject goOn; private GameObject goOff; // Start is called before the first frame update void Start() { smiley = GameObject.CreatePrimitive(PrimitiveType.Sphere); smiley.name = "Smiley"; mr = smiley.GetComponent(); smiley.transform.position = transform.position + new Vector3(0, -0.2f, -0.2f); smiley.transform.Rotate(new Vector3(0, -90, 0)); smiley.transform.parent = transform; mr.material = SmileyMat; } private void OnEnable() { Valve.VR.InteractionSystem.Player.OnHeadsetOn += ShowPlayer; Valve.VR.InteractionSystem.Player.OnHeadsetOff += HidePlayer; } private void OnDisable() { Valve.VR.InteractionSystem.Player.OnHeadsetOn -= ShowPlayer; Valve.VR.InteractionSystem.Player.OnHeadsetOff -= HidePlayer; } private void ShowPlayer() { goOn = Instantiate(HitEffectOn, smiley.transform); StartCoroutine("DelayPlayer"); } private IEnumerator DelayPlayer() { yield return new WaitForSeconds(0.2f); mr.enabled = true; } private void HidePlayer() { goOff = Instantiate(HitEffectOff, smiley.transform); mr.enabled = false; } }