Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;
public class AI : MonoBehaviour {
public Transform target;
private Vector3 Target, direction;
public float Speed, Rotation_Speed,Attack_Distance, FireDistance, heath, Timer;
private float distance, TimerDown;
public GameObject bullet, FirePrefab;
public Transform FirePoint;
private bool play;
public AudioClip FireSound;
public AudioSource source;
// Use this for initialization
void Start () {
TimerDown = Timer;
if(target == null)
{
target = GameObject.FindGameObjectWithTag("Player").transform;
}
}
// Update is called once per frame
void Update () {
Target = target.transform.position;
distance = Vector3.Distance(Target, transform.position);
if(distance <= Attack_Distance)
{
direction = Target - transform.position;
direction.y = 0;
if(distance > FireDistance)
{
transform.position = Vector3.Lerp(transform.position, Target, Time.deltaTime * Speed);
}
else
{
if(!play)
{
play = true;
}
if (TimerDown > 0)
TimerDown -= Time.deltaTime;
if (TimerDown < 0)
TimerDown = 0;
if (TimerDown == 0)
{
Fire ();
TimerDown = Timer;
}
}
transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation(direction), Rotation_Speed * Time.deltaTime);
}
if(heath <= 0)
{
Destroy(gameObject);
}
}
void Fire()
{
if(play)
{
source.PlayOneShot(FireSound);
Instantiate(bullet, FirePoint.position, FirePoint.rotation);
Instantiate(FirePrefab, FirePoint.position, FirePoint.rotation);
play = false;
}
}
void OnTriggerEnter(Collider other)
{
if( other.tag == "Space" ){
heath -=10;
}
}
}
using System.Collections;
public class AI : MonoBehaviour {
public Transform target;
private Vector3 Target, direction;
public float Speed, Rotation_Speed,Attack_Distance, FireDistance, heath, Timer;
private float distance, TimerDown;
public GameObject bullet, FirePrefab;
public Transform FirePoint;
private bool play;
public AudioClip FireSound;
public AudioSource source;
// Use this for initialization
void Start () {
TimerDown = Timer;
if(target == null)
{
target = GameObject.FindGameObjectWithTag("Player").transform;
}
}
// Update is called once per frame
void Update () {
Target = target.transform.position;
distance = Vector3.Distance(Target, transform.position);
if(distance <= Attack_Distance)
{
direction = Target - transform.position;
direction.y = 0;
if(distance > FireDistance)
{
transform.position = Vector3.Lerp(transform.position, Target, Time.deltaTime * Speed);
}
else
{
if(!play)
{
play = true;
}
if (TimerDown > 0)
TimerDown -= Time.deltaTime;
if (TimerDown < 0)
TimerDown = 0;
if (TimerDown == 0)
{
Fire ();
TimerDown = Timer;
}
}
transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation(direction), Rotation_Speed * Time.deltaTime);
}
if(heath <= 0)
{
Destroy(gameObject);
}
}
void Fire()
{
if(play)
{
source.PlayOneShot(FireSound);
Instantiate(bullet, FirePoint.position, FirePoint.rotation);
Instantiate(FirePrefab, FirePoint.position, FirePoint.rotation);
play = false;
}
}
void OnTriggerEnter(Collider other)
{
if( other.tag == "Space" ){
heath -=10;
}
}
}