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入门操作_视频_036
- Unity入门操作_协程_023
- Unity入门操作_动画系统_Mecanim_032
- Unity入门操作_ 规律移动_007
- Unity入门操作_刚体 _012
- Unity入门操作_动画系统_Legacy_031
- Unity入门操作_旋转_006
- Unity入门操作_碰撞器 _013
- unity shader 之 CG(C for graphics) 入门(2)——CG的Swizzle操作
- Unity入门操作_固定路线行走_021
- Unity入门操作_025_01
- Unity入门操作_UGUI_事件_030
- Unity入门操作_音频_035
- Unity入门操作_关节,布料_017
- Unity入门操作_PlayerPrefs存储_037
- 【笨木头Unity】入门之旅009:Demo之四处找死(四)_在代码里操作物体
- Unity入门操作_鼠标寻路 _020
- Unity入门操作_Transform组件_003
- Unity入门操作_UGUI_ScrollBar_029
- 【笨木头Unity】入门之旅005:正常人都要掌握的操作