- Home /
Disable Sprite when keypress (Working Script, just need disble)
Hello guys!
I made this script and you are free to use it. When you press ,1,2,3 a sprite will display. What I need is when you press
,1,2,3 a sprite will disable and enable the other one. So it's like when you press 1, 1 will disable and enable 2 rather then just display sprites all in all when you press the buttons. Hope you can help! thanks. Here is the script.
var Weapon1: Sprite;
var Weapon2: Sprite;
var Weapon3: Sprite;
var Weapon4: Sprite;
var sprite : SpriteRenderer;
function Start ()
{
sprite = GetComponent(SpriteRenderer);
}
function Update ()
{
if(Input.GetKey(KeyCode.Alpha2))
{
sprite.sprite = Weapon1;
}
if(Input.GetKey(KeyCode.Alpha1))
{
sprite.sprite = Weapon2;
}
if(Input.GetKey(KeyCode.Alpha3))
{
sprite.sprite = Weapon3;
}
if(Input.GetKey(KeyCode.BackQuote))
{
sprite.sprite = Weapon4;
}
}
your current script changes a single weapon Picture with button presses?
And you want to enable/disable different pictures at different location with button presses?
Thanks for your answers, yes at the moment the sprite that displays just displays and the others stay there too. So when you press 1, 2 will display but 1 will still display. I want to enable/disable each picture when you press the buttons. I tried Renderer.Disable = true however it's not actually working
Thanks for your answers, Yes what I need is when you press 1 key for example a sprite will display, then when you press 2 key the 1 key sprite will disable and only enable the 2 sprite. At the moment each key you press will only display a sprite which is working, I just need something like Renderer.disable/enable for each sprite however can't get it to work .. argh.
Already tried that, however it didn't work. Anyone have other solution? :)