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 Kthibodeau2009 · May 21, 2012 at 02:11 PM · translationcasting

Error, class project

Everytime I input this code it says I have to enter a ";" after every word. Can someone fix this?

 public var pickupPrefab:GameObject;
 public var numberOfPickups:int = 2;
 private var spawnPointList:GameObject[];
 private var spawnIndexAvailableList:Array = [];
 private var numberOfSpawnPoints:int;
 function Awake()
 {
     GameObject which this script is a Component of
     spawnPointList = gameObject.FindGameObjectsWithTag("SpawnPoint");
     numberOfSpawnPoints = spawnPointList.length;
     if (numberOfPickups > numberOfSpawnPoints)
         numberOfPickups = numberOfSpawnPoints;
     for (var i:int = 0; i < numberOfSpawnPoints; i++)
     {
         spawnIndexAvailableList[i] = true;
     }
     for (var j:int = 0; j < numberOfPickups; j++)
     {
         SpawnPickup();
     }
 }
 function SpawnPickup()
 {
     the list
     var randomSpawnIndex:int = Random.Range(0, numberOfSpawnPoints);
     while (!spawnIndexAvailableList[randomSpawnIndex])
     {
         randomSpawnIndex = Random.Range(0, numberOfSpawnPoints);
     }
     var spawnedPickupPosition:Vector3 = spawnPointList[randomSpawnIndex].transform.position;
     var spawnedPickupRotation:Quaternion = spawnPointList[randomSpawnIndex].transform.rotation;
     var spawnedPickup:GameObject = Instantiate(pickupPrefab, spawnedPickupPosition, spawnedPickupRotation);
     that this script is a Component of pickupPrefab to call functions within this sript
     spawnedPickup.transform.parent = spawnPointList[randomSpawnIndex].transform;
     spawnedPickup.name = randomSpawnIndex.ToString();
     spawned in this position
     spawnIndexAvailableList[randomSpawnIndex] = false;
 }
Comment
Add comment · Show 6
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 Berenger · May 21, 2012 at 02:48 PM 0
Share

I usually correct the formatting of people's code, but you don't even have a proper indentation. Please clean it up, select all the code and click the code button (the one with 101 010). Or you can be sure no one will ever answer your question .

avatar image bompi88 · May 21, 2012 at 02:49 PM 0
Share

All I see is a cluster of letters. Please format your code. I think I can see where your error may occur, but with this messy code I'm really not sure.

avatar image syclamoth · May 21, 2012 at 02:53 PM 0
Share

I'm afraid that before I can fix your code, someone is going to have to fix you.

avatar image Bunny83 · May 21, 2012 at 03:13 PM 2
Share

I tried formatting the code, but there's a bug in the qato editor. The last part of the post is not in the editable text but appears in the post...

edit There wasn't a bug in the editor. It was just the code that still had some newlines within one of the long lines.

@$$anonymous$$thibodeau2009: Have you ever heard about comments? You can't just write a letter to your friend in between your code.

Single line comments look like this:

 // This is a comment

Comments that go over multiple lines looks like this:

 /* This is a real
    long comment across
    multiple lines */

Comments are ignored by the compiler. Everything else have to be valid code.

avatar image Kthibodeau2009 · May 22, 2012 at 12:27 AM 0
Share

I did this really quick at the end of class because I just couldn't figure out what was wrong with my $$anonymous$$chers code. Thank you @Bunny83 for not complaining and actually helping. But i know how to do commentary, it was all my $$anonymous$$chers terrible example script that caused the problems. Thanks again.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · May 21, 2012 at 03:47 PM

This is the most ineffective and dangerous way to pick random spawn points.

This is a simplified and more robust version and furthermore doesn't contain errors ;)

 import System.Collections.Generic;
 
 public var pickupPrefab : GameObject;
 public var numberOfPickups : int = 2;
 private var spawnPointList : GameObject[];
 private var availableSpawnPoints : List.<GameObject>;
 
 function Awake()
 {
     spawnPointList = gameObject.FindGameObjectsWithTag("SpawnPoint");
     // create a dynamic copy of the spawnpoint array
     availableSpawnPoints = new List.<GameObject>(spawnPointList);
     
     if (numberOfPickups > availableSpawnPoints.Count)
         numberOfPickups = availableSpawnPoints.Count;
     for (var j = 0; j < numberOfPickups; j++)
     {
         SpawnPickup();
     }
 }
 
 function SpawnPickup()
 {
     if (availableSpawnPoints.Count <= 0)
         return; // No more spawnpoints left
     var randomSpawnIndex : int = Random.Range(0, availableSpawnPoints.Count);
     var spawnPoint : Transform = availableSpawnPoints[randomSpawnIndex].transform;
     // remove this spawn point from the available list
     availableSpawnPoints.RemoveAt(randomSpawnIndex);
     
     var spawnedPickup:GameObject = Instantiate(pickupPrefab, spawnPoint.position, spawnPoint.rotation);
     
     spawnedPickup.transform.parent = spawnPoint;
     spawnedPickup.name = randomSpawnIndex.ToString();
 }
Comment
Add comment · 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

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

8 People are following this question.

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

Related Questions

Problem with type casting from C# to JS 3 Answers

Children ignoring Parent control. [Solved] 1 Answer

tilt function for moving the character left and right 1 Answer

Touch input on IOS C# 0 Answers

Translating an Array of Transforms 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