using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class csStateAI : MonoBehaviour {
public float rotSpeed = 100f;
public float movSpeed = 10f;
public float sightLenth = 10f;
public float sightAngle = 30f;
public Transform[] targets;
public Transform target;
int curArray;
Transform tr;
Vector3 dir;
// Use this for initialization
void Start () {
tr = GetComponent<Transform>();
target = GetComponent<Transform>();
}
void dirUpdate(int curArray) // 순서 1 : 방향 백터 갱신
{
target = targets[curArray].GetComponent<Transform>();
dir=target.position - this.transform.position;
}
bool distanceCheck(int curArray) // 순서 2 : 거리 계산
{
target = targets[curArray].GetComponent<Transform>();
float distance = (target.position - tr.position).magnitude;
if (distance <= sightLenth) return true;
else return false;
}
bool angleViewCheck() // 순서 3 : 시야각 계산
{
float Angle = Vector3.Angle(tr.forward, dir);
if (Angle <= sightAngle) return true;
else return false;
}
void allCheck()
{
for (int num = 0; num < targets.Length; num++)
{
dirUpdate(num);
distanceCheck(num);
angleViewCheck();
}
}
//
// Update is called once per frame
void Update () {
transform.Translate(new Vector3(0, 0, Input.GetAxis("Vertical")) * movSpeed * Time.deltaTime);
float angSpeed = Input.GetAxis("Horizontal") * rotSpeed * Time.deltaTime;
transform.Rotate(Vector3.up * angSpeed);
Debug.DrawRay(transform.position, Vector3.forward * sightLenth,Color.red);
Vector3 angleSight = Quaternion.AngleAxis(sightAngle / 2, transform.up) * transform.forward;
Debug.DrawRay(transform.position, angleSight * sightLenth, Color.red);
angleSight= Quaternion.AngleAxis(-sightAngle / 2, transform.up) * transform.forward;
Debug.DrawRay(transform.position, angleSight * sightLenth, Color.red);
RaycastHit rch;
if ()
{
if(true==Physics.Raycast(tr.position, tr.forward * sightLenth,out rch))
{
csTargetType ot =rch.transform.GetComponent<csTargetType>();
if (null != ot)
{
if(ot.)
}
}
}
}
}
댓글 0