Changing plane image on keystroke

Is there a way to change the image assigned to a plane based on keystroke or mouseclick? I can’t seem to find anything that allows for this.

This isn’t possible in Unity unfortunately… unless you read the manual of course :wink:

Check out these sections to get you started:

Welcome to the forums and please feel free to ask further, more specific, questions regarding this subject in this thread… I’ll be happy to help.

Thank you for the direction.

Is it non standard to attempt to animate a sprite on a flat plain in unity? I think this is called procedural animation, where it’d be kinda like making a cartoon on a flat plain instead of using a 3d character.

This is for a 2d game, from what I’ve seen so far, people are using 3d objects and removing a dimension to give the 2d look and feel. Is the way I suggested possible? ill advised? the way?

No, it’s not non-standard at all. It’s just that there are an infinite number of combinations so “change image based on keystroke” isn’t a built-in feature. But it’s most certainly simple and straightforward to:

  1. Detect a keystroke and respond to that…
  2. By changing the image used on a flat plane

:slight_smile:

how do you do a pause in between frames?

if (Input.GetButton (“Jump”)) {
moveDirection.y = jumpSpeed;
for(i=0;i<10;i++){
var c = i + “”; // to make c a string w/ i’s value
renderer.material.mainTexture = Resources.Load(c);
}
}
}

??? I want this to go through 10 pics for the jumping animation, but it seems to happen instantly… As it should without a pause. How do we do pauses?

Coroutines. Don’t lump all that into your Update function, instead have that funciton call an animation function that uses a coroutine (because Update functions can’t use them). For example:

function Update () {
  if (Input.GetButton ("Jump")) {
    moveDirection.y = jumpSpeed;
    FlipTextures();
  }
}

function FlipTextures () {
  for(i=0;i<10;i++){
    var c = i + ""; // to make c a string w/ i's value
    renderer.material.mainTexture = Resources.Load(c);
    yield WaitForSeconds(0.1);
  }
}

The way I have it written above will cause the animation to span a total of 1 second (a for loop of 10 iterations, each one pauses for 0.1 seconds). Read up on WaitForSeconds and the like (yield, StartCoroutine, etc.), they’re very useful for animation routines like this.

thank you kindly sir. Things are coming along =)