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 Glinny · Aug 11, 2012 at 08:10 AM · errorcompiler

Compiler error??

This is the code I am using to make a simple character have AI, why isn't it working? It says that 'Assets/AIgremlin.js(15,1): BCE0044: expecting }, found ''.' My code is this

 #pragma strict

 function Start ()
 {
     var theplayer : GameObject;
     var speed : float;
     var range : int;
     var explosion : GameObject;
 }
 
 function Update ()
 {
     range = Vector3.Distance(theplayer.transform.rotation,transform.position);
     if (range < 40)
     {
         transform.LookAt(theplayer.transform.position);
     }
Comment
Add comment · Show 3
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 Glinny · Aug 11, 2012 at 09:53 AM 0
Share

This code is receiving the error "Assets/AIgremlin.js(15,1): BCE0044: expecting }, found ''." can someone please explain why this is.

#pragma strict function Start () { var theplayer : GameObject; var speed : float; var range : int; var explosion : GameObject; } function Update () { range=Vector3.Distance(theplayer.transform.rotation,transform.position); if (range&lt;40){ transform.LookAt(theplayer.transform.position); }

avatar image whydoidoit · Aug 11, 2012 at 09:55 AM 0
Share

I've converted your answer to a comment, on Unity Answers - Answer means solution and not reply. There's an add new comment button hidden on the right of the screen.

I have also formatted your code- to do this either indent your code by 4 spaces or 1 tab before pasting or highlight it all and click the code button after pasting.

avatar image Glinny · Aug 12, 2012 at 01:05 AM 0
Share

$$anonymous$$y codes working now but the enemy doesn't look at me, is there a problem with my code?

 #pragma strict

 function Update ()
 {
     var theplayer : GameObject;
     var speed : float;
     var range : int;
     var explosion : GameObject;
     range=Vector3.Distance(theplayer.transform.position,transform.position);
     if (range<40)
     {
         transform.LookAt(theplayer.transform.position);
     }
 }    

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by whydoidoit · Aug 11, 2012 at 09:50 AM

Well

  1. You appear to be defining variables inside Start when they should be outside of it to allow other functions to access them.

  2. You are finding the distance between a rotation and a position which doesn't make sense!

Comment
Add comment · Show 3 · Share
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 Glinny · Aug 11, 2012 at 10:56 AM 0
Share

How would I fix this??

avatar image whydoidoit · Aug 11, 2012 at 11:08 AM 0
Share

Well put the variables outside Start and use position not rotation

avatar image Bunny83 · Aug 12, 2012 at 01:16 AM 0
Share

@Glinny @seth-bergman
I removed your two comments since they are not longer relevant and the whole question is already kinda messy.

avatar image
0

Answer by Bunny83 · Aug 12, 2012 at 01:14 AM

I guess you want your script to look like this:

 #pragma strict
 
 var theplayer : GameObject;
 var range : float = 40.0;
 
 function Update ()
 {
     var distance = Vector3.Distance(theplayer.transform.position, transform.position);
     if (distance < range)
     {
         transform.LookAt(theplayer.transform.position);
     }
 }

I've removed everything that isn't used anywhere by this script. Of course you have to assign your player gameobject to the "theplayer" variable in the inspector

Comment
Add comment · Show 3 · Share
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 Glinny · Aug 12, 2012 at 01:21 AM 0
Share

When I move the enemy moves too, why is that?

avatar image Glinny · Aug 12, 2012 at 01:23 AM 0
Share

Also how do you record sounds in Unity?

avatar image Bunny83 · Aug 12, 2012 at 03:35 AM 0
Share

@Glinny: To your first quiestion: I have no idea. This script doesn't move anything, it just rotates the object so the z axis looks towards the given object. $$anonymous$$aybe you attached the player controller script to your enemy as well?

Your second question has nothing to do with my answer nor with the question you've asked here, so post it as a new question if you can't find the solution on UnityAnswers. This might help

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

10 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

Related Questions

Multiple Cars not working 1 Answer

Tons of compiler Errors.. Please help ;_; 1 Answer

Assets/cubeAI.js(2,11): UCE0001: ';' expected. Insert a semicolon at the end. 1 Answer

Internal Compiler Error 1 Answer

Complete Packages wont run correctly in Unity 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