HI all !!! i’m totally new to unity and scripting so i’m having some problems wich i think are very basic level…
Well first: I have i Gui text with the score and would like to have a script that reads the score and increases the pitch of a AudioFile if the score is more than a certain number…
Second: if a certain object is hit, after a 5 second wait a particular object in the game should be placed back to his starting position
Third: I use the marble tutorial script for the score,
var score : Score;
function Update () {
}
function OnCollisionEnter (collision : Collision) {
score.AddToScore ();
}
is it possible to have differrent scores sent to the score gui for different objects hit??? Essentially can i change the score value this script sends to the the one on the GuiText ???
Thanks a lot just for reading my more than ignorant questions
Hope for Help…
I’m not sure about what you want to do, but as far as I understand you just want to set the GUI Text score value. If this is what you want then you can extend the “Score”-script with a set-function.
var score = 0;
function AddToScore() {
++score;
guiText.text = "Score: " + score.ToString();
}
function SetScore(score_value) {
guiText.text = "Score: " + score_value.ToString();
}
Then you can call this SetScore function from anywhere else.
Actually what I need is the opposite , I should be able to read the value of the score from another script, and if score value is more than 50 do something
Thanks Again,
but then now what do I have to put in another script, to access score and if > 10 play sound ???
Sorry but I really now nothing about coding… tryng to learn but…
Just call this script Respawn.js and attach it to each of the objects you want to respawn … in this case, when you hit the space bar anything with this attached will reset to its starting position …
var respawnPosition: Vector3;
function Awake() {
// this saves the objects original position
respawnPosition=transform.position;
}
function Update () {
if (Input.GetButton ("Jump")) {
transform.position = respawnPosition;
}
}
It creates a variable named “respawnPosition” that is a 3D position. It notes this when the level starts and then function Update listens every frame for the space bar being pressed. If it detects the spacebar it transforms the positon of the object back to the start.
You can of course replace the spacebar condition with any other … losing a life, falling below a certain Y height, etc.
var respawnPosition: Vector3;
function Awake() {
// this saves the objects original position
respawnPosition=transform.position;
}
function Update () {
if ("my condition is met") {
transform.position = respawnPosition;
}
}
In this case, if the object falls down below a certain Y value (i.e., off a platform into space) it’ll reset …
var respawnPosition: Vector3;
function Awake() {
// this saves the objects original position
respawnPosition=transform.position;
}
function Update () {
if (transform.position.y < -35) {
transform.position = respawnPosition;
}
}
var respawnPosition: Vector3;
function Awake() {
// this saves the objects original position
respawnPosition=transform.position;
}
function Update () {
if (Input.GetButton ("Jump")) {
transform.position = respawnPosition;
}
}
great thanks!!!
Do, how do i tell him to respawn if it hits a certain object?
and, is there a way to tell him to wait before respawn?
Real thanks to eveybody, the unity community is incredible!!!
Now don’t quote me on this and some other 15 year old genius will toodle along soon to write this correctly but here it is commented …
var respawnPosition: Vector3;
function Awake() {
// this saves the objects original position
respawnPosition=transform.position;
}
"if a collision happens" () {
yield WaitForSeconds (5);
transform.position = respawnPosition;
}
Something like that. I’ll move aside now for a real coder to write it correctly …