- Home /
Question by
PaxStyle · Feb 10, 2014 at 03:08 PM ·
key pressedmaterial.
Use the same input key
Hi guys, i tried to set this script for use the same input key, but it dosn't work.. How can I do?
using UnityEngine;
using System.Collections;
public class Luci4 : MonoBehaviour {
public Material material1;
public Material material2;
void Start () {
renderer.material = material1;
}
void Update () {
if (Input.GetKeyDown (KeyCode.Alpha4))
{
if (Material != material1)
{
Material = material1;
}
else
{
Material = material2;
}
}
}
}
Comment
Answer by Ashish Dwivedi · Feb 10, 2014 at 04:09 PM
This is the correct code.
using UnityEngine;
using System.Collections;
public class Cube4: MonoBehaviour {
public Material material1;
public Material material2;
void Start () {
renderer.material = material1;
}
void Update () {
if (Input.GetKeyDown (KeyCode.Alpha4))
{
if (renderer.material != material1)
{
renderer.material = material1;
}
else
{
renderer.material = material2;
}
}
}
}
Your answer
Follow this Question
Related Questions
How to create a countdown counter based off of a Key press. 1 Answer
Inspector doesn't want to show keys in Scripts 2 Answers
Highlight one cell on a GridObject (prefab included) 2 Answers
Key Press to Trigger animation when within range 1 Answer
Can I reset the InputManager's Axes with a script? 2 Answers