- Home /
Question by
CrilleStyles · May 02, 2014 at 08:45 PM ·
script.function update
Combinate 2 scripts to disable a function?
How do I conbine these 2 script and then deactivate the fire function till R is pressed?
#pragma strict
var bulletPrefab : Transform;
var player : GameObject;
var force : float = 2000;
var shootForce : float = 1000;
function Update () {
if(Input.GetMouseButtonDown(0)){
fire();
}
}
function fire(){
var instanceBullet = Instantiate(bulletPrefab,transform.position,Quaternion.identity);
instanceBullet.rigidbody.AddForce(transform.forward*shootForce);
}
//And then we have the deactivate script
var Enabled : boolean;
private var counter : int;
function Start () {
Enabled = true;
}
function Update () {
if(Input.GetKeyUp(KeyCode.R)){
Enabled = true;
}
if(Input.GetKeyUp(KeyCode.Mouse0)){
counter += 1;
}
if(counter == 7){
Enabled = false;
counter = 0;
}
}
Comment
Why don't you take a shot at combining them. If you get stuck, then ask us for help. Looking at this code, the only rule you need to know is that you cannot have the same function twice in a file. That means you will need to combine the code from the two Update() functions into a single function.
Your answer
Follow this Question
Related Questions
Script is causing crashes and i Don't know what to do. 2 Answers
How to stop player movement slowly fade down? 1 Answer
Calculate frame rate 2 Answers
Mirror reflecting another mirror ... 1 Answer