holopy3/Assets/Scripts/SmileySpawner.cs

61 lines
1.7 KiB
C#
Raw Normal View History

2020-12-10 14:25:12 +00:00
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>();
2020-12-12 18:29:31 +00:00
//Transform MicroSub
//smiley.transform.position = transform.position + new Vector3(0, -0.2f, -0.2f);
//Transform for normal PlayerController
smiley.transform.position = transform.position;
2020-12-10 14:25:12 +00:00
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;
}
}