Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed Oct 01, 2015 at 08:27 AM by cadeautje for the following reason:

I found the answer myself

avatar image
0
Question by cadeautje · Sep 30, 2015 at 01:01 PM · c#random.rangelocalscale

how to scale an object on instantiate with a random value

I am trying to spawn birds with a random scale which works but I can only scale the x y and z individual and not the xyz at the same time (with the same random value)

this is my script:

using UnityEngine; using System.Collections;

public class BirdScript : MonoBehaviour { public float wait; public GameObject Bird; public Vector3 spawnValues;

 void Start () 
 {
     StartCoroutine ( spawnBirds() );
 }


 IEnumerator spawnBirds()
 {
     for(int i = 0 ; i < 2 ; i++)
     {
         Vector3 spawnPosition = new Vector3 (spawnValues.x ,Random.Range (8f, 25f) , spawnValues.z);
         Instantiate (Bird, spawnPosition , Quaternion.identity);
         Vector3 scale = Bird.transform.localScale;
         scale.x = Random.Range (1f, 5f);
         Bird.transform.localScale = scale;
         i = 0;
         yield return new WaitForSeconds (wait);
     }

 }

}

any help would be greatly appreciated.

Comment
Add comment
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

1 Reply

  • Sort: 
avatar image
1

Answer by Eric5h5 · Sep 30, 2015 at 01:09 PM

You need to scale the object you're instantiating, not the prefab. Instantiate returns a reference to that object, so you assign it to a variable. In any case, simply assign the same value to x, y, and z.

Comment
Add comment · Show 5 · 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 cadeautje · Sep 30, 2015 at 01:26 PM 0
Share

But if I do that they wont have the same random value, x might be 1 while y could 5 I need the xyz to get the same random value

avatar image Eric5h5 cadeautje · Sep 30, 2015 at 02:06 PM 0
Share

So just use Random.Range once and apply that to them all.

avatar image cadeautje Eric5h5 · Sep 30, 2015 at 02:26 PM 0
Share

and that is what I cant get to work and am asking help about, how do I use it once to apply it to them all?

Show more comments
avatar image cadeautje · Oct 01, 2015 at 08:27 AM 0
Share

Well, I honestly have no idea what you mean, but I made it work by simply making the X have a random value and making the Y and Z equal to the X

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Two objects sharing a script should spawn different random objects, but instead they spawn the same random object. 1 Answer

I can not modify localscale while I'm playing because of the Animator. 1 Answer

Use Different Gameobjects based on Local Scale? 0 Answers

What range of values need to be inserted if we need to pull a random item from the list? 0 Answers

continuously spawning and causes spawned objects to overlap 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