using UnityEngine;
using System.Collections;
public class Clicker : MonoBehaviour {
// Use this for initialization
void Start () {
}
public Transform target; //目标
public Seeker controler; //搜素类的一个对象
RaycastHit hit; //光
public LayerMask mask; //一个层
public GameObject building; //一个物体 建筑物
// Update is called once per frame
void Update () {
if (Input.GetKeyDown ("mouse 0")) {
Ray ray = camera.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray,out hit,1000F,mask)) {
target.position = hit.point; //目标的点等于光点
controler.StartPath (controler.transform.position,target.position); //搜素出发的路径当前的位置到目标的位置
}
}
if (Input.GetKeyDown ("p")) {
Ray ray = camera.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray,out hit,1000F,mask)) {
target.position = hit.point; //光的碰撞点为目标点
GameObject go = Instantiate (building,hit.point,Quaternion.identity) as GameObject; //生成一个building
AstarPath.active.SetNodes (false,go.collider.bounds,true);
}
Debug.Log ("Set Nodes"); //输出一个信息
}
}
}