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 /
This question was closed Nov 09, 2014 at 05:26 PM by robertbu for the following reason:

Multiple technical questions, lack of context

avatar image
0
Question by ivikd · Nov 09, 2014 at 05:22 PM · instantiaterandomspawn

How to generate random object with attributes?

Hello all.

I'm working on a 2D game where i need a new object to be generated every few seconds somewhere in the screen. This object can be one of 20 items, divided into 4 categories (cat1, cat2, cat3, cat4). Each category has 5 different images to pick from, but technically all objects in cat1, for example, behave identically except for the image file attached to them. I've read that I can use an Instantiate method to spawn my objects, but I'm not sure how I would go about setting it up to pick a category and an image from it.

So far, I've managed to instantiate my object in a random position (restricted a bit):

  var myObject : Transform;
  function Update()
  {
      Instantiate(myObject,new Vector3(UnityEngine.Random.Range(-3f,3f),UnityEngine.Random.Range(-3f,3f),UnityEngine.Random.Range(-3f,3f)), Quaternion.identity);
  }

However, this is using the gameObject with a preset image for its sprite via the Sprite Renderer component. Ideally, I'd want it to randomly select an image from my assets folder.

Any help would be much appreciated!

Comment
Add comment · Show 1
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 robertbu · Nov 09, 2014 at 05:27 PM 0
Share

There are multiple technical questions here, and there is not enough context to give you an accurate answer to the most obvious one...how to change a texture of a game object. Unity Answers addresses a single, specific technical question.

To start, research the many ways the texture can be change. Do some goggling on the follow:

  • $$anonymous$$aterial.mainTexture

  • sprite sheet

  • texture atlas

  • uv coordinates

  • material.mainTextureOffset and $$anonymous$$aterial.mainTextureScale

  • texture array

  • Resources.Load() and Resources.LoadAll()

  • Sprite

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Object Spawning Randomly 0 Answers

Why do objects keep spawning on top of one another? 0 Answers

Random select from array and spawn 1 Answer

Creating a light in game C# 1 Answer

How can I align instantiated prefabs randomly on runtime #C 0 Answers


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