- Home /
Really simple animation/movement question
Hello my names Chris ,
I've just started using unity and I'm currently creating a 2d platformer, I'm stuck on something I feel there's an extremely simple answer but it's just not working for me. Upon clicking the d key I would like to load up the material for the character movement animation and for it to return to the original stationary material upon releasing from the d key. What is the goddamn code for this?
Answer by photex · Oct 05, 2012 at 12:02 AM
Provided that you've created and setup two materials in the editor you can use public variables in your MonoBehavior to refer to these materials and then just assign them to your gameObject given the conditions you've outlined:
if (Input.GetKeyDown(KeyCode.D)) {
gameObject.renderer.material = my_running_material;
} else if (Input.GetKeyUp(KeyCode)) {
gameObject.renderer.material = my_standing_material;
}
This is not a code snippet you should use verbatim. It's just to illustrate the basic approach.
Your answer
Follow this Question
Related Questions
how to make your own character. 2 Answers
mystery RestartLevel function used in official tutorial 2 Answers
Character controller + animation of different meshes making one character 1 Answer
Animation Movement 1 Answer
Charater Movement 1 Answer