holopy3/Assets/Scripts/SmileySpawner.cs
2020-12-12 19:29:31 +01:00

60 lines
1.7 KiB
C#

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<MeshRenderer>();
//Transform MicroSub
//smiley.transform.position = transform.position + new Vector3(0, -0.2f, -0.2f);
//Transform for normal PlayerController
smiley.transform.position = transform.position;
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;
}
}