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 /
avatar image
0
Question by VortexInCortex · Jun 05, 2019 at 12:21 AM · spriteparticle systemmask

How can I make my spritemask have a random rotation and size when it spawns?

I have a sprite mask with the shape of a blood stain alt text When I kill an enemy that sprite mask appears and reveals the blooded map. alt text

So I want to make my sprite mask have a random size and rotation, but I really don't know how to do that. Maybe by code (I'm a noob at code so I'd need a tutorial), or with the particle system?

The particle system looks like the best Idea, but I'm not sure if the particle system could spawn sprite masks.

screenshot-69.png (108.9 kB)
screenshot-70.png (312.7 kB)
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
0
Best Answer

Answer by highpockets · Jun 05, 2019 at 05:54 AM

Doing this by code will be easiest. For random size right after the line that you spawn/Instantiate the sprite:

 spriteMask.transform.localScale = new Vector2(Random.Range(0.5f, 2.0f), Random.Range(0.5f, 2.0f));

That will set a random size between 0.5 units and 2 units on the x and y axis, but if you want to keep it square, you should add a float before that line and put the random range method in there, then put that float variable where I put BOTH the random range methods.


For rotation, do the same with random range, but you only need to apply it to the z axis:

 spriteMask.transform.rotation.eulerAngles = new Vector3(sprite.transform.rotation.eulerAngles.x, sprite.transform.rotation.eulerAngles.y, Random.Range(0.0f, 360.0f));

That should do it.

Comment
Add comment · Show 7 · 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 VortexInCortex · Jun 05, 2019 at 11:05 AM 0
Share

Oh, um I'm gonna try but I don't instantiate(I donn't know what instantiate means so I'm just gonna look for it.) my blood mask. It's a part of my particle system, prefab, which means it spawns when the particle system comes in place (Which occurs when a zombie dies or hits the player.).

Oh, I found that it was creating an object, well I didn't actually do that by script as I said before :/. I'm gonna see if I'm able to find a place for those lines in my script alt text

avatar image highpockets VortexInCortex · Jun 05, 2019 at 11:24 AM 0
Share

Doing something like this without script will be hard. $$anonymous$$aybe a component is out there that randomizes scale and rotation of Sprite$$anonymous$$asks when they spawn, but I don’t know of one. I don’t think there is a way to do this without coding a bit. I know of a visual scripting add on for unity called Bolt, but I’ve never used it. You could maybe attempt with that, but I’m quite sure there will be limitations with what you can accomplish

avatar image VortexInCortex highpockets · Jun 05, 2019 at 11:38 AM 0
Share

I didn't say I didn't want to do it by script, it's just my sprite mask isn't instantiated by script ^^.

avatar image VortexInCortex · Jun 05, 2019 at 11:27 AM 0
Share

I tried your script, but unity says I need a reference. I don't know how to show that to unity :/ alt text alt text Oh, yea also I wanna keep it a square, but I didn't get your explanation of the float. so, for now, it's gonna be an ugly rectangle :/

screenshot-74.png (70.3 kB)
screenshot-75.png (29.1 kB)
avatar image VortexInCortex VortexInCortex · Jun 05, 2019 at 11:34 AM 0
Share

These are my errors alt text

screenshot-77.png (24.1 kB)
avatar image highpockets VortexInCortex · Jun 05, 2019 at 11:59 AM 0
Share

Just delete Sprite$$anonymous$$ask and Sprite from everywhere in the script as this is on the transform. You will be able to do what you need by simply accessing the transform since the script is on the sprite game object:

  transform.localScale = new Vector2(Random.Range(0.5f, 2.0f), Random.Range(0.5f, 2.0f));
    transform.rotation.eulerAngles = new Vector3(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, Random.Range(0.0f, 360.0f));
avatar image VortexInCortex highpockets · Jun 05, 2019 at 12:05 PM 0
Share

THAN$$anonymous$$ YOU SO $$anonymous$$UCH!

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

213 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 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

Default Sprite Mask 2D not working on mobile 0 Answers

Why my c# for load sprite in spritemask does'n work? 0 Answers

Two sprite-mask for one sprite 0 Answers

Sprites are invisible when passed between scenes 1 Answer

sprites / diffuse does not support rectmask 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