• 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 zephman8001 · Jun 23, 2014 at 10:55 PM · scriptingproblem

';' Insert semicolon here... Its already there

 #pragma strict
 
 var Health = 130;
 
 function Update ()
 {
     if(Health <= 0)
     {
         ChoppedDown();
     }
 }
 
 function ApplyDammage (TheDammage : int)
 {
     Health -= TheDammage;
 }
 
 function ChoppedDown()
 {
     GameObject FallingTree = (GameObject)Instantiate(FallingTree, Paling01_a.transform.position, Paling01_a.transform.rotation);
     Destroy(Paling01_a);
 }

It wants me to add 2 extra semicolons to line 20. Someone please help

Comment
Add comment · Show 4
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 rutter · Jun 23, 2014 at 10:53 PM 2
Share

You're using C# syntax in a JS file.

You want something more like this:

 var FallingTree = Instantiate(FallingTree, Paling01_a.transform.position, Paling01_a.transform.rotation) as GameObject;
avatar image zephman8001 · Jun 23, 2014 at 10:55 PM 0
Share

This causes more errors

avatar image zephman8001 · Jun 24, 2014 at 01:48 AM 0
Share

I am not sure, but Paling01_a is in the prefabs folder and so is FallingTree

avatar image zephman8001 · Jun 24, 2014 at 01:49 AM 0
Share

I'm pretty new to Unity so thank you in advance if you can help me get through this

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by jefjohms · Jun 23, 2014 at 11:58 PM

You are using the variable "FallingTree" as your original Object parameter in the Instantiate function. This is the same name used in the variable you are creating on the left side of the assignment. I imagine this is confusing the syntax checking.

You need to provide an Object for Instantiate to clone. This can be done by adding a public variable 'FallingTreePreFab' gameObject and dragging a prefab to in Unity. You then can assign your GameObject FallingTree to the clone.

 **public GameObject FallingTreePreFab;**
 
 function ChoppedDown()
 {
 
 GameObject FallingTree = (GameObject)Instantiate(**FallingTreePreFab**, Paling01_a.transform.position, Paling01_a.transform.rotation);
     Destroy(Paling01_a);
 
 }



Comment
Add comment · Show 4 · 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 AlucardJay · Jun 24, 2014 at 01:01 AM 1
Share

Well spotted so +1, but unfortunately you have also got some C# mixed in with uJS (probably inherited from copy-paste) ;)

You can format the code by highlighting it, then clicking the 101010 button.

avatar image zephman8001 · Jun 24, 2014 at 01:53 AM 0
Share

Okay can you explain in detail what the stuff in the 6th line is saying exactly

avatar image zephman8001 · Jun 24, 2014 at 01:54 AM 0
Share

I'm trying to get this to work in a JavaScript btw

avatar image jefjohms · Jun 24, 2014 at 04:54 PM 0
Share

Line 6 is the same as your code only switching out the variable FallingTree for the variable FallingTreePreFab created in line 1.

You are right, I use C# for scripting so that is where my answer came from. I'm no JScript expert but I think your code is mixing C# as well. JScript is weak typed so your original line 20 should be as rutter suggested above:

 var FallingTree = Instantiate(FallingTreePreFab, Paling01_a.transform.position, Paling01_a.transform.rotation) as GameObject;

And line 1 in my answer should probably be:

 var FallingTreePreFab : GameObject;

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

unity 3.4 crashes when i get to a certain point in the character generator script? 0 Answers

How to create a UnityScript array and access the data in each cell. 1 Answer

Help me to fix my script error cs1519 1 Answer

How to delete animation event from .fbx file using script 0 Answers

Swapping animation clips at runtime 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