sorry i’ve never played GTA, but do you want it to just rotate constantly? If this is all you want to do the easiest way would be (in my opinion) this script.
Javascript:
var RotateSpeed:float=1;//speed of rotation
var YisTop:boolean=false;
var XisTop:boolean=false;
var ZisTop:boolean=false;
// some objects have different tops, meaning their rotations will be different on the ground, so choose which one works for the weapon
function Update(){
if (YisTop){
transform.rotation=Quaternion.Euler(Vector3(0,Time.time*RotateSpeed,0));
} else if (XisTop){
transform.rotation=Quaternion.Euler(Vector3(Time.time*RotateSpeed,0,0));
} else {
transform.rotation=Quaternion.Euler(Vector3(0,0,Time.time*RotateSpeed));
}
}
C#: (after the public class is stated)
Float RotateSpeed=1;
Bool YisTop=false;
Bool XisTop=false;
Bool ZisTop=false;
// some objects have different tops, meaning their rotations will be different on the ground, so choose which one works for the weapon
Void Update(){
if (YisTop){
transform.rotation=Quaternion.Euler(Vector3(0,Time.time*RotateSpeed,0));
} else if (XisTop){
transform.rotation=Quaternion.Euler(Vector3(Time.time*RotateSpeed,0,0));
} else {
transform.rotation=Quaternion.Euler(Vector3(0,0,Time.time*RotateSpeed));
}
}
mind you these are not tested and their may be a few error codes. Hope this helped :lol:
var i : int;
var Speed : float;
var Player : GameObject;
function Update() {
for( i = 0; i < 1;){
transform.Rotate(Vector3.right * Speed);
}
function OnTriggerEnter() {
i = 1;
Player.transform.parent = transform;
}
}
But you’ll still have a loop that never exits.
Without a yield or return, Unity gets inside the function and cannot escape, so the infinite-loop handler crashes Unity “more gracefully” rather than let it hang forever.
You need to store a state somewhere that enables/disables
spinning.
e.g.
private var spin : boolean = true;
function Update () {
if ( spin )
// spin;
}
function OnTriggerEnter( -- ) {
if ( -- ) {
spin = false;
}
}
Totally, Vicenti. The update function never ends! In fact, there isn’t any reason to use a loop for the spinning. Each time ‘update’ gets call you only need to rotate a few degrees, and only once. ‘Update’ is already like an endless ‘for’ loop.