I am really really new to scripting and this week we are without guidance on how to create a speedometer for a vehicle. As resources we are given 25 .png’s of a speedometer going from 0-120. I thought if I used a GUI texture I could use a switch function, except now my lack of experience with scripting has caught up to me. I have this much on the script so far (I tried to cheese the switch using the input instead of a direct correlation to the speed of a ridgidbody)
var imgSpeedo_00 : Texture2D;
var imgSpeedo_01 : Texture2D;
var imgSpeedo_02 : Texture2D;
var imgSpeedo_03 : Texture2D;
var imgSpeedo_04 : Texture2D;
var imgSpeedo_05 : Texture2D;
var imgSpeedo_06 : Texture2D;
var imgSpeedo_07 : Texture2D;
var imgSpeedo_08 : Texture2D;
var imgSpeedo_09 : Texture2D;
var imgSpeedo_10 : Texture2D;
var imgSpeedo_11 : Texture2D;
var imgSpeedo_12 : Texture2D;
var imgSpeedo_13 : Texture2D;
var imgSpeedo_14 : Texture2D;
var imgSpeedo_15 : Texture2D;
var imgSpeedo_16 : Texture2D;
var imgSpeedo_17 : Texture2D;
var imgSpeedo_18 : Texture2D;
var imgSpeedo_19 : Texture2D;
var imgSpeedo_20 : Texture2D;
var imgSpeedo_21 : Texture2D;
var imgSpeedo_22 : Texture2D;
var imgSpeedo_23 : Texture2D;
var imgSpeedo_24 : Texture2D;
var imgSpeedo_25 : Texture2D;
function Update () {
switch(Input.GetKeyDown(KeyCode.UpArrow))
// this is where I begin to get lost, Im not sure if i need an external script to interact with in order to make the switch work
{
case 0:
guiTexture.texture = imgSpeedo_00;
break;
case 1:
guiTexture.texture = imgSpeedo_01;
break;
case 2:
guiTexture.texture = imgSpeedo_02;
break;
case 3:
guiTexture.texture = imgSpeedo_03;
break;
//ETC…
}
}
would this be able to work with some tweaking, or should I rethink on how to change the texture of the GUI as my ridgidbody’s speed increases. If I do need to use the speed in order to make the speedometer work, would I have to create a static variable for that? like
static var speed : float = 0;
?
I guess what I am getting at is that I need help with basic scripting that I can’t really get from my teacher (very hands off instructor)
anything you guys can help with is awesome, any resources that can walk me through and hold my hand while it does so would be awesome.