|
I'm making a "2D platformmer in a 3D world" like game, and the main character is a cube, with a sprite printed on it. The cube is very thin, so you cannot see the sides from the angle I'm rendering the game. Anyway, I want to change the texture of the player when the player starts running, and when he stops. Here's the code I'm attempting to use:
I've associated the correct materials to the variables, but when I run the script, an error comes up the first time I attempting to change texture:
Also, the texture doesn't change at all. Do any of you guys know how I can do this?
(comments are locked)
|
|
Ok I fixed the problem, I just changed the "OnGetButtonDown" in the moving left and right for "OnGetButton", and added two bools to check in which direction the player is moving. Here is the code, tested and working ;D:
(comments are locked)
|
|
You put quotation marks in the bottom. Those are strings, not textures. But your variables aren't textures, either. They're materials. So get rid of all of the .mainTexture's, too. This will help your code break at compile time instead of runtime: http://forum.unity3d.com/threads/71445-How-To-Set-Project-Wide-pragma-Directives-with-JavaScript Thankyou for your answer, but I have one more problem now. The player can mess us the texture by pressing both the keys at once. Is there a way to prevent that?
May 16 '11 at 11:16 AM
Biendeo
Run different delegates ("Function types") depending on state. http://unity3d.com/support/documentation/Manual/MonoUpgradeDetails.html
May 16 '11 at 12:58 PM
Jessy
I'm not quite sure what you mean from that. I don't really know how to implement that into the script. Can you help me?
Jun 11 '11 at 11:26 PM
Biendeo
(comments are locked)
|
|
Ok so your script could go like this:
What where you doing wrong was:
I tested it and it works, I hope this helps you :D I like your script, but there's one thing that I think should be fixed. Say you're running right. Pressing left while running right will change the texture to the movingLeft, and then changes it to the stillLeft when you let go of the left key, all while moving right. Do you know how to fix this?
Jun 12 '11 at 01:25 AM
Biendeo
(comments are locked)
|
