您的位置:首页 > 移动开发 > Unity3D

Unity入门操作_ 吊桥_022

2017-08-26 11:57 411 查看


需要注意的是吊桥要当做移动障碍物处理(区别在于要先烘焙一下)。

using UnityEngine;

using System.Collections;

private NavMeshAgent play;
// Use this for initialization
void Start () {
play = GetComponent<NavMeshAgent>();
}
// Update is called once per frame
void Update () {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray,out hit))
{
if (Input.GetMouseButtonUp(0))
{
play.SetDestination(new Vector3(hit.point.x, play.transform.position.y, hit.point.z));
}
}
}


}

using UnityEngine;

using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

float time;
float time1;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
time += Time.deltaTime;
time1 += Time.deltaTime;
if (time>=5)
{
if (time1>=5)
{
transform.Rotate(Vector3.back,60);
time1 -= 10;
}
else
{
transform.Rotate(Vector3.forward, 60);
}
time -= 5;
}
}


}

//上面的程序有点小瑕疵,用下面这种需要在原桥面上需要加一个移动障碍物。

using UnityEngine;

using System.Collections;

public class Drawbridge : MonoBehaviour {

//计时器
float time;
//开关时间
public float duration;
bool isOpen= true;
public GameObject obstacle;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
time += Time.deltaTime;
if (time>duration)
{
if (isOpen)
{
transform.Rotate(Vector3.right * 60, Space.World);
}
else
{
transform.Rotate(Vector3.right * -60, Space.World);
}
obstacle.SetActive(isOpen);
isOpen = !isOpen;
time -= duration;
}
}


}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  unity 移动