- Home /
Changing a Sprite when Collision occurs
Hi,
I've been trying to figure out how I would do a code that would be for my University project on a 2D Sidescroller Spaceship game.
The way this works is when the spaceship crashes in to a collider, I want the sprite to change to a different one which will be the same sprite, just I added a darker effect to it in Photoshop, and as it hits the collider of three times, eventually the GameObject will destroy and the level will fade out and restart.
Would it be best to do this on JS or C#? Can anyone get me started? :)
Answer by Jeff-Kesselman · Nov 11, 2014 at 02:16 PM
In general the answer is you create the new object in the scene, copy the transform matrix from the old one, and delete the old one.
Alternately, you could avoid the transform copy by making the object have an empty parent object and just replace the children.
As for your second question, if this is going to be anything more then a quick small demo you should use C#. Javascript (really Unityscript, which is a close cousin of Javascript) can seem easier at first but any real game project quickly grows out into a level of complexity Unityscript can't manage.
Answer by Jaz30 · May 14, 2018 at 02:03 AM
Check this out, I've created a tutorial for this :) https://www.youtube.com/watch?v=ma5OBfPRxcg&list=PLiIYE_N6GMrZgLF5fgPNxavmOr3t5RRkv