Documentation for the Unity C# Library
Loading...
Searching...
No Matches
CollisionUIVisualiser.cs
Go to the documentation of this file.
1using PixoVR.Core;
2using System;
3using System.Collections;
4using System.Collections.Generic;
5using UnityEngine;
6using UnityEngine.UI;
7
8public class CollisionUIVisualiser : MonoBehaviour
9{
10 public GameObject CollisionPrefab;
11
12 private void Awake()
13 {
14 EventBetter.Listen(this, (CollisionMessage msg) => DrawCollision(msg.reporter, msg.collision));
15 }
16
17 private void DrawCollision(Collider reporter, Collision collision)
18 {
19 var vis = GameObject.Instantiate(CollisionPrefab, transform);
20 var camera = Camera.main;
21
22 var screenPoint = camera.WorldToScreenPoint(collision.contacts[0].point);
23 vis.transform.position = screenPoint;
24 vis.GetComponent<Text>().text = reporter.name + " with " + collision.gameObject.name;
25 }
26
27}
void DrawCollision(Collider reporter, Collision collision)
Intentionally made partial, in case you want to extend it easily.