• 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
Question by forrest117 · May 31, 2011 at 01:00 AM · javascriptrandomweaponmario kart

Mario Kart Style random weapon

I want to make a mario style game and i want to make it so that a game object will give me a random weapon when i drive over it and also the object would have to respawn after a few seconds. Please help

Comment

People who like this

0 Show 0
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

3 Replies

  • Sort: 
avatar image

Answer by Flafla2 · May 31, 2011 at 01:12 AM

This is a situation where if you actually knew Unityscript you would know what the solution is... Let's go through your question by looking at Key words: I want to make a mario style game and i want to make it so that a game object will give me a random weapon when i drive over it and also the object would have to respawn after a few seconds. Please help

Alright, the first keyword is game object. So you need to have a gameobject in your scene, and call it a certian name.

Random:Duh... Random.Range

Drive Over It: Colliders. Rigidbodies. Yay.

Respawn: Instantiate the "Item box" gameobject.

A few Seconds: Time, *Time*, ***Time!***

I hope this answers your question.

Comment
SrBilyon
SirGive

People who like this

2 Show 0 · 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

Answer by save · May 31, 2011 at 01:05 AM

You could do this on OnTriggerEnter(), select a random object with Random.Range(minval, maxval) and make use of yields to wait for the respawn (could be the objects renderer switch on/off).

Comment

People who like this

0 Show 2 · 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 forrest117 · May 31, 2011 at 01:13 AM 0
Share

But could i use Arrays with it? and how would i go about that exactaly in script? sorry im a noob

avatar image save · May 31, 2011 at 02:04 AM 0
Share

Yeah you definitely could apply an array to it, just use var weaponOfRandomChoice : GameObject = weapons[Random.Range(0, weapons.length)]. The array itself could store the actual GameObjects or otherwise integers, it all depends on how you want to wrap things up to finally give the randomized weapon to the player.

avatar image

Answer by eeveelution8 · May 10, 2014 at 07:10 PM

I don't know how to do it either, but here's a good starting script to go with.

 var items : GameObject [];
  
 function OnTriggerEnter()
 {
     collider.enabled = false;
  
     var index : int = Random.Range(1,items.length);
     var thePrefab : GameObject = items[index];
  
     var instance : GameObject = Instantiate(thePrefab, transform.position, transform.rotation);
  
 }
Comment

People who like this

0 Show 0 · 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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to create random movement in 2D 2 Answers

GameObject variable change for all of the objects 1 Answer

ramdomised weapon pickup 1 Answer

Random Music Track on Load 1 Answer

how do i implement probability in java script 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