64
edits
Line 95: | Line 95: | ||
———Unity script ————————————————————————————————————————————<br> | ———Unity script ————————————————————————————————————————————<br> | ||
The monuments change angles and always face to the visitor.Here I use tangent trigonometric | |||
function.<br> | |||
———Unity script ————————————————————————————————————————————<br> | |||
using System.Collections;<br> | |||
using System.Collections.Generic;<br> | |||
using UnityEngine;<br> | |||
public class movewithcamera : MonoBehaviour {<br> | |||
float radian ;<br> | |||
void Start () {<br> | |||
}<br> | |||
void Update () {<br> | |||
var rotationVector = transform.rotation.eulerAngles;<br> | |||
radian = Mathf.Atan (Mathf .Abs (Camera.main.transform.position.x -<br> | |||
transform.position.x)/Mathf .Abs (Camera.main.transform.position.z -<br> | |||
transform.position.z));<br> | |||
if(Camera.main.transform.position.x >transform.position.x &<br> | |||
Camera.main.transform.position.z < transform.position.z){<br> | |||
rotationVector.y = - (radian * 180) / Mathf.PI ;<br> | |||
} else if(Camera.main.transform.position.x < transform.position.x &<br> | |||
Camera.main.transform.position.z > transform.position.z){<br> | |||
rotationVector.y = - (radian * 180) / Mathf.PI ;<br> | |||
}else if(Camera.main.transform.position.x < transform.position.x &<br> | |||
Camera.main.transform.position.z < transform.position.z){<br> | |||
rotationVector.y = (radian * 180) / Mathf.PI ;<br> | |||
}else{<br> | |||
rotationVector.y = (radian * 180) / Mathf.PI ;<br> | |||
}<br> | |||
transform.rotation = Quaternion.Euler(rotationVector);<br> | |||
}<br> | |||
}<br> | |||
———Unity script ————————————————————————————————————————————<br> | |||
<br clear="all" /> | <br clear="all" /> |
edits