- Home /
C# Script Not Working? (AdvancedAI)
Here's the script:
using UnityEngine; using System.Collections;
public class AdvancedAI : MonoBehaviour { public float Lives = 100; private GameObject player; public float speed = 2.0f; private int Smart = 0; public float Gravity = 9.81f; public float RotationSpeed = 40; public float DeathTime = 5; public CharacterController cc; enum State { Idle, Find, Attack, Death, End, } private State state; // Use this for initialization void Start () { state = AdvancedAI.State.Idle; StartCoroutine(); } IEnumerator () { while (true) { switch (state) { case State.Idle: Idle(); break; case State.Attack: Attack(); break; case State.Find: Find(); break; case State.Death: Death(); break; case State.End: End(); break; } yield return null; }
}
void Idle () {
if (player == null) {
state = AdvancedAI.State.Find;
}
else {
state = AdvancedAI.State.Attack;
cc.Move(transform.TransformDirection(-Vector3.up * Gravity * Time.deltaTime));
}
}
void Attack () {
if (Lives<=0) {
state = AdvancedAI.State.Death;
}
else {
if(cc.isGrouded==false) {
Idle();
}
animation["InjuredWalk"].enabled = true;
animation["InjuredWalk"].normalizedSpeed = Speed;
Vector3 currentPos = player.transform.position - transform.position;
Quaternion rot = Quaternion.LookRotation(currentPos);
cc.Move(transform.TransformDirection(Vector3.forward * Speed * Time.deltaTime));
transform.rotation = rot;
}
}
void Find() {
animation["InjuredWalk"].warpMode = WarpMode.Loop;
animation["InjuredWalk"].enabled = false;
player = GameObject.FindGameObjectWithTag("Player");
state = AdvancedAI.State.Idle;
}
void Death () {
Lives = 0;
Destroy(cc);
animation["InjuredWalk"].enabled = false;
//Destroy (gameObject)
state = AdvancedAI.State.End;
}
void End () {
}
}
Any clue why it is not working?
the first part of your code is not formatted, so it's almost impossible to read. click "Edit" to fix!
You will need to explain what is not working.
Are you adding this to a c# script? $$anonymous$$ake sure you're not adding it to a javascript file.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
looking to make for a zombie script AI,navmesh or not? 2 Answers
Evade a Collider on Vector3.forward 3 Answers
FPS Kit AI and Animation 0 Answers
Distribute terrain in zones 3 Answers