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 /
avatar image
0
Question by saloo165 · Dec 30, 2017 at 04:15 PM · instantiatetransformprefabslocalscale

Prefab color is black

Hello , I am making a simple game in which the player have to dodge from the falling obstacles . Its all working fine but with just adding two lines of code the prefab color become black .

if (Time.time > nextSpawnTime) {

         nextSpawnTime = Time.time + spawnDuration;

         // Generating randon X Pos and specific Y Pos
         float randomSpawnPosition = Random.Range (-halfScreenSizeUnits, halfScreenSizeUnits);
         float initiatePoint = Camera.main.orthographicSize + 2;

         // Generating position for Blocks
         Vector2 spawnPosition = new Vector2 (randomSpawnPosition, initiatePoint);

         float randomSpawnAngle = Random.Range (-spawnAngle, spawnAngle); 

         GameObject newBlock = (GameObject)Instantiate (enemyPrefab, spawnPosition, Quaternion.Euler(Vector3.forward * randomSpawnAngle));

         float spawnSize = Random.Range (spawnSizeMinMax.x, spawnSizeMinMax.y);
         newBlock.transform.localScale = Vector2.one * spawnSize;
     }

So here everything is fine . The problem is in the last two lines . If I comment these 2 lines then the prefab instantiate randomly and with its own color but if I remove the comment the prefabs becomes black . what's the problem with that ?

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

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by SandScorp · Dec 31, 2017 at 09:05 AM

Hi,

Edited my answer after reviewing I noticed you are using a vector2.

Using a Vector2 this will set the Z value of localScale to 0 automatically because localScale is a vector3. If one of the values of localScale is 0, it would prevent the lighting from affecting it alltogether. Using a vector3 instead of a vector2 would be enough to fix your issue.

So it would end up looking like this:

 newBlock.transform.localScale = Vector3.one * spawnSize;
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

107 People are following this question.

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

Related Questions

Instantiating and setting localScale doesn't work 1 Answer

Access a prefab from a child class 3 Answers

Getting instance of an sub object rather than the original's subobject 0 Answers

Not your typical "Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption" 0 Answers

How can you make a Instanciate prefab follow a scene object? 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