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
When I kill an enemy that sprite mask appears and reveals the blooded map. 
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.
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.
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 
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
I didn't say I didn't want to do it by script, it's just my sprite mask isn't instantiated by script ^^.
I tried your script, but unity says I need a reference. I don't know how to show that to unity :/
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 :/
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));
THAN$$anonymous$$ YOU SO $$anonymous$$UCH!
Your answer
