- 最后登录
- 2019-12-25
- 注册时间
- 2012-8-24
- 阅读权限
- 90
- 积分
- 71088
 
- 纳金币
- 52352
- 精华
- 343
|
墙挡上物体的时候,摄像机不断向上移动知道看到物体- using UnityEngine;
- using System.Collections;
- public class GUIManager : MonoBehaviour {
- private GameObject player;
- private Vector3 camPos;
- // Use this for initialization
- void Start () {
- player = GameObject.Find("player");
- camPos = transform.position;
- }
- public Ray ray;
- public RaycastHit hit;
- void Update () {
- ray = new Ray(player.transform.position, player.transform.position - transform.position);
- if (Physics.Raycast(ray, out hit, 100))
- {
- if (hit.transform.name != "player")
- {
- transform.Translate(Vector3.up * Time.deltaTime);
- transform.LookAt(player.transform.position);
- }
- else if (transform.position.y != camPos.y)
- {
- transform.Translate(Vector3.down * Time.deltaTime);
- transform.LookAt(player.transform.position);
- }
- }
- }
- }
复制代码 |
|