Hey all,
So here’s my script, i can’t see why it’s not working, but again i’m new to the scripting scene. I have all the code there, i’m trying to center my high score GUI using the GUI Matrix (So on android phones it will adjust to the relevant position and size, aka center) as well as implement the +1 coin count on collision that will change the gui text on collision with the Coin.
I’m sorry if this makes no sense, It’s late here in Australia, and this script is stressing me out
Script:
var originalWidth = 1080; // define here the original resolution
var originalHeight = 1920; // you used to create the GUI contents
var score = 3f;
private var scale: Vector3;
function OnControllerColliderHit (hit : ControllerColliderHit){
if(hit.gameObject.name == "Coin")
{
score = score-1;
}
function Update(){
GameObject.Find("GUI Text").guiText.text = "x"+score;
}
function OnGUI(){
scale.x = Screen.width/originalWidth; // calculate hor scale
scale.y = Screen.height/originalHeight; // calculate vert scale
scale.z = 1;
var svMat = GUI.matrix; // save current matrix
// substitute matrix - only scale is altered from standard
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale);
// draw your GUI controls here:
//...
// restore matrix before returning
GUI.matrix = svMat; // restore matrix
}
Sorry if its a bit messy, but if you could maybe help that’d be great!
Thank you so much in advance,
-Fersuta