- Home /
Question by
Klousianic · Jun 28, 2015 at 07:31 AM ·
javascripttimegravityspawnfalling
change gravity after time
Hi everyone, I have spawners, which create very 5 sceonds some objects. Now I want, that they change every 5 seconds the gravity too, but how can I change it? Sorry for bad english, thank you!
var cube : GameObject;
var spawnPosition : GameObject;
var timer = 0.0;
function SpawnCube() {
var tempCubeSpawner = Instantiate(cube, spawnPosition.transform.position, Quaternion.identity);
}
function Update() {
timer += Time.deltaTime;
if(timer > 5) {
var randomNumber = Random.Range(0.0f,1.0f);
if(randomNumber < 0.5f) {
SpawnCube();
timer = 0.0;
// Here change the gravity
}
else {
timer = 0.0;
}
}
}
Comment
Answer by komodor · Jun 28, 2015 at 07:31 AM
Ok, but how can I increase the gravity, so that the object fall after 5 seconds faster?
well gravity is global setting, so it won't affect just one object
but you can just call
Physics.gravity = new Vector3(vhatever 3 comma separated float values you want);
and the gravity will change
Your answer
Follow this Question
Related Questions
falling faster after time 1 Answer
Random spawn timer 1 Answer
varibals coincidence 1 Answer
Js: UnityEngine.Rigidbody is required, how to fix? 2 Answers
Can I access Physics2dSettings in Project Settings via script 1 Answer