У меня есть такой игровой обьект как "Волк", он должен гнаться за игроком если тот входит в его триггер, а также уходить на свою точку дома если игрок вышел из триггера, также в игре имеется ракетница, и волк должен убегать(пока на точку дома), если выстрел произошел в зоне его триггера, но он это упорно не делает....
*Скрипты сырые и недоработанные, представляют из себя примерный план, позже уже доработаю, пока делаю ток основные функции.
Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;
public class AI : MonoBehaviour {
public UnityEngine.AI.NavMeshAgent Agent;
public Transform Home;
public Transform Player;
public int CurrentO;
void Update () {
if (CurrentO == 0) {
GetComponent<Animation> ().Play ("Idle");
}
if (CurrentO == 1) {
GetComponent<Animation> ().Play ("Walk");
Agent.SetDestination (Home.position);
}
if (CurrentO == 2) {
GetComponent<Animation> ().Play ("Running");
Agent.SetDestination (Player.position);
}
}
}
using System.Collections;
public class AI : MonoBehaviour {
public UnityEngine.AI.NavMeshAgent Agent;
public Transform Home;
public Transform Player;
public int CurrentO;
void Update () {
if (CurrentO == 0) {
GetComponent<Animation> ().Play ("Idle");
}
if (CurrentO == 1) {
GetComponent<Animation> ().Play ("Walk");
Agent.SetDestination (Home.position);
}
if (CurrentO == 2) {
GetComponent<Animation> ().Play ("Running");
Agent.SetDestination (Player.position);
}
}
}
Синтаксис:
Используется csharp
using System.Collections;
using UnityEngine;
public class Gun : MonoBehaviour {
public Transform Bulletpref;
public Transform Pivot;
public int Ammo;
public AudioClip ShoоtAudio;
public int Hit;
// Use this for initialization
void Start () {
Ammo = 6;
}
// Update is called once per frame
void Update () {
if (Ammo < 0) {
Ammo = 0;
}
if (Ammo > 6) {
Ammo = 6;
}
if (Input.GetMouseButtonDown(0)){
Ammo = Ammo - 1;
}
if (Input.GetMouseButtonDown(0) && Ammo >= 0 && Ammo <= 6 ){
Instantiate (Bulletpref,Pivot.position,Pivot.rotation);
Hit = 1;
gameObject.GetComponent<AudioSource>().clip = ShoоtAudio;
gameObject.GetComponent<AudioSource>().Play();
}
else {
Hit = 0;
}
}
}
using UnityEngine;
public class Gun : MonoBehaviour {
public Transform Bulletpref;
public Transform Pivot;
public int Ammo;
public AudioClip ShoоtAudio;
public int Hit;
// Use this for initialization
void Start () {
Ammo = 6;
}
// Update is called once per frame
void Update () {
if (Ammo < 0) {
Ammo = 0;
}
if (Ammo > 6) {
Ammo = 6;
}
if (Input.GetMouseButtonDown(0)){
Ammo = Ammo - 1;
}
if (Input.GetMouseButtonDown(0) && Ammo >= 0 && Ammo <= 6 ){
Instantiate (Bulletpref,Pivot.position,Pivot.rotation);
Hit = 1;
gameObject.GetComponent<AudioSource>().clip = ShoоtAudio;
gameObject.GetComponent<AudioSource>().Play();
}
else {
Hit = 0;
}
}
}
Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;
public class Attack : MonoBehaviour {
public AI _AI;
public Gun hit;
void OnTriggerEnter(Collider Player){
if (Player.gameObject.tag == "Player") {
_AI.CurrentO = 2;
}
}
void OnTriggerExit(Collider Player){
if (Player.gameObject.tag == "Player") {
_AI.CurrentO = 1;
}
}
void OnTriggerStay(Collider Player)
{
if(Player.gameObject.tag == "Player" && hit.Hit == 1) {
_AI.CurrentO = 1;
}
}
}
using System.Collections;
public class Attack : MonoBehaviour {
public AI _AI;
public Gun hit;
void OnTriggerEnter(Collider Player){
if (Player.gameObject.tag == "Player") {
_AI.CurrentO = 2;
}
}
void OnTriggerExit(Collider Player){
if (Player.gameObject.tag == "Player") {
_AI.CurrentO = 1;
}
}
void OnTriggerStay(Collider Player)
{
if(Player.gameObject.tag == "Player" && hit.Hit == 1) {
_AI.CurrentO = 1;
}
}
}
Что-то писал сам, что-то нашел на просторах интернета