Create a Personal 3D Gallery Project with Unity
Use the [first person controller](First Person All-in-One) in asset store
Model scale ~= Cube 40*40
Add Component->Physic->Mesh Collider to models
Light: turn off shadow & increase range to 20
Sound effect for different walking materials
Change Material in Mesh Collider, not Mesh Renderer
Add UI->Text
When setting Rect Transform, press Alt(Option) to set position as well
Add Tag to Text
Add Image: Drag jpg onto Plane
Close to display text
drag script onto image
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class Proximity : MonoBehaviour { public string newTitle; public string newAuthor; public string newDesc; private Transform other; private Text myTitle; private Text myAuthor; private Text myDesc; private float dist; private GameObject player; private GameObject message1; private GameObject message2; private GameObject message3; private bool check;
// Start is called before the first frame update void Start() { player = GameObject.FindWithTag("Player"); other = player.GetComponent<Transform>(); message1 = GameObject.FindWithTag("ArtTitle"); message2 = GameObject.FindWithTag("ArtAuthor"); message3 = GameObject.FindWithTag("ArtDescription"); myTitle = message1.GetComponent<Text>(); myTitle.text = ""; myAuthor = message2.GetComponent<Text>(); myAuthor.text = ""; myDesc = message3.GetComponent<Text>(); myDesc.text = ""; check = false; }
// Update is called once per frame void Update() { if (other) { dist = Vector3.Distance(transform.position, other.position); print("Distance to player: " + dist); if (dist < 4) { myTitle.text = newTitle; myAuthor.text = newAuthor; myDesc.text = newDesc; check = true; } if (dist > 4 && check == true) { Start(); } } } }
|