Sorry about the actual title not being very informative (Didn’t know what to write).
But here’s my question;
I have this script, and currently you need to actually press the GUI button on the screen to make it trigger the camera shake.
But, I want it to get rid of the GUI button, and replace that with a simple Left Mouse Click to trigger the camera shake.
And if possible, Can you show me how to make it wait 2 seconds before the camera shake actually starts?
var originPosition:Vector3;
var originRotation:Quaternion;
var shake_decay: float;
var shake_intensity: float;;
function OnGUI () {
if (GUI.Button (Rect (20,40,80,20), "Shake")) {
Shake();
}
}
function Update(){
if(shake_intensity > 0){
transform.position = originPosition + Random.insideUnitSphere * shake_intensity;
transform.rotation = Quaternion(
originRotation.x + Random.Range(-shake_intensity,shake_intensity)*.2,
originRotation.y + Random.Range(-shake_intensity,shake_intensity)*.2,
originRotation.z + Random.Range(-shake_intensity,shake_intensity)*.2,
originRotation.w + Random.Range(-shake_intensity,shake_intensity)*.2);
shake_intensity -= shake_decay;
}
}
function Shake(){
originPosition = transform.position;
originRotation = transform.rotation;
shake_intensity = .3;
shake_decay = 0.002;
}
Thanks for taking the time to read this, and hopefully someone may be able to help me, Because I’ve been sitting here for a few hours trying, and I’m getting no where.
-Brayden