Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by LukaKotar · Dec 24, 2011 at 02:24 PM · c#iosaizombie

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?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · Dec 24, 2011 at 03:45 PM 0
Share

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.

avatar image ByteSheep · Dec 24, 2011 at 05:08 PM 0
Share

Are you adding this to a c# script? $$anonymous$$ake sure you're not adding it to a javascript file.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges