Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by mlimon · Apr 11, 2017 at 06:46 PM · unexpected-symbol

What needs to be changed in the coding for it to work again from a tutorial from Aaron Hibberd?

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Monster : MonoBehaviour {

 public GameObject player;
 public AudioClip[] footsounds;

 private UnityEngine.AI.NavMeshAgent nav;
 private AudioSource sound;
 private Animator anim;
 private string state = "idle";
 private bool alive = true 

 // Use this for initialization
 void Start() {

     nav = GetComponent<UnityEngine.AI.NavMeshAgent> ();
     sound = getcomponent<AudioSource> ();
     anim = getcomponent<Animator> ();
     nav.speed = 1.2f;
     anim.speed = 1.2f;
 }

 public void footstep( int _num)
 {
     sound.clip = footsounds [_num];
     sound.Play ();

 }
 
 // Update is called once per frame
 void Update () {

     if{alive){
     
     anim.SetFloat ("velocity", nav.velocity.magnitude);
     nav.SetDestination (player.transform.position);

             //Idle//
             if(state == "idle")
             {
                 //pick a random place to walk//
                 vector3 randomPos = Random.insideUnitSphere*20f;
                 NavMeshHit navHit;
                 navMesh.SamplePosition(transform.position + ranDomPos, out navHit,20f,NavMesh.AllAreas);
                 nav.SetDestination(navHit.Position);
                 state = "walk";
             }
             //walk//
             if(state == "walk")
             {
                 if(nav.remainingDistance <= nav.stoppingDistance && !nav.pathPending)
                 {
                     state = "idle";
                 }
         }
 }

 }

}

Comment
Add comment · Show 5
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 hexagonius · Apr 11, 2017 at 08:39 PM 0
Share

What's broken?

avatar image mlimon · Apr 11, 2017 at 10:18 PM 0
Share

Nothing is broken. I was co$$anonymous$$g back to work on it and it came up with 8 errors on the script when I was testing it. Just wondering if it is the program messing with the code structure or something has changed through an update.

avatar image Positive7 mlimon · Apr 11, 2017 at 10:26 PM 0
Share

You have around 4-5 typo, Unity (well c#) is case sensitive.

getcomponent should be : GetComponent ranDomPos should be : randomPos nav$$anonymous$$esh.SamplePosition.... should be Nav$$anonymous$$esh.SamplePosition .... nav.SetDestination(navHit.Position); should be nav.SetDestination(navHit.position);

private bool alive = true missing ";" at end of the line : private bool alive = true;

if{alive){ should be if(alive){

avatar image mlimon · Apr 11, 2017 at 10:53 PM 0
Share

Thanks for the help. That cleared out 4 out of the eight. It is still having issues with void start. Im not sure why since the script came with that.

avatar image Positive7 mlimon · Apr 11, 2017 at 10:56 PM 0
Share
 using UnityEngine;
 
 public class $$anonymous$$onster : $$anonymous$$onoBehaviour
 {
     public GameObject player;
 
     public AudioClip[] footsounds;
 
     private Nav$$anonymous$$eshAgent nav;
 
     private AudioSource sound;
 
     private Animator anim;
 
     private string state = "idle";
 
     private bool alive = true;
 
     private void Start()
     {
         this.nav = this.GetComponent<Nav$$anonymous$$eshAgent>();
         this.sound = this.GetComponent<AudioSource>();
         this.anim = this.GetComponent<Animator>();
         this.nav.speed = 1.2f;
         this.anim.speed = 1.2f;
     }
 
     public void footstep(int num)
     {
         this.sound.clip = this.footsounds[num];
         this.sound.Play();
     }
 
     private void Update()
     {
         if (this.alive)
         {
             this.anim.SetFloat("velocity", this.nav.velocity.magnitude);
             this.nav.SetDestination(this.player.transform.position);
 
             // Idle//
             if (this.state == "idle")
             {
                 // pick a random place to walk//
                 var randomPos = Random.insideUnitSphere * 20f;
                 Nav$$anonymous$$eshHit navHit;
                 Nav$$anonymous$$esh.SamplePosition(this.transform.position + randomPos, out navHit, 20f, Nav$$anonymous$$esh.AllAreas);
                 this.nav.SetDestination(navHit.position);
                 this.state = "walk";
             }
 
             // walk//
             if (this.state == "walk")
             {
                 if ((this.nav.remainingDistance <= this.nav.stoppingDistance) && !this.nav.pathPending)
                 {
                     this.state = "idle";
                 }
             }
         }
     }
 }

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

100 People are following this question.

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

Related Questions

Assets/Scripts/GenerateLandscape.cs(41,60): error CS1525: Unexpected symbol `true' 1 Answer

Why do I have errors on all of my private declarations and on my void update? 1 Answer

Unexpected symbol error 0 Answers

Can someone Help Me Unexpected Symbol '(' in class, struct ,or interface 2 Answers

Unexpected symbol `object' in class, struct, or interface member declaration. 1 Answer


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