- Home /
Question by
CrilleStyles · Apr 10, 2014 at 05:14 PM ·
vector3.project
Mixing together 2 scripts?
How can I make thees 2 scripts into one?
#pragma strict
public var floatSpeed = .5;
function Update() {
if (Physics.Raycast (transform.position, Vector3.down, 5.0)) {
rigidbody.transform.position += Vector3.up * floatSpeed * Time.deltaTime;
rigidbody.drag = 20.0;
}
else{
rigidbody.drag = 1.0;
}
}
static var selectedId : int;
static var speed : int = 90;
function Update (){
if (selectedId==GetInstanceID()) {
if (Input.GetKey (KeyCode.UpArrow)) transform.Translate (Vector3(0,0,1) * Time.deltaTime*speed);
if (Input.GetKey (KeyCode.DownArrow)) transform.Translate (Vector3(0,0,-1) * Time.deltaTime*speed);
if (Input.GetKey (KeyCode.Space)) transform.Translate (Vector3(0,1,0) * Time.deltaTime*speed);
if (Input.GetKey (KeyCode.LeftControl)) transform.Translate (Vector3(0,-1,0) * Time.deltaTime*speed);
if (Input.GetKey(KeyCode.RightArrow))
transform.Rotate(Vector3.up * speed * Time.deltaTime);
if (Input.GetKey(KeyCode.LeftArrow))
transform.Rotate(-Vector3.up * speed * Time.deltaTime);
}
}
function OnMouseDown () {
selectedId = GetInstanceID();
}
Comment
Best Answer
Answer by Malfegor · Apr 10, 2014 at 06:12 PM
If your 'Mix together' is really all you want, then there's nothing more easy.
#pragma strict
public var floatSpeed = .5;
static var selectedId : int;
static var speed : int = 90;
function Update() {
if (Physics.Raycast (transform.position, Vector3.down, 5.0)) {
rigidbody.transform.position += Vector3.up * floatSpeed * Time.deltaTime;
rigidbody.drag = 20.0;
}
else{
rigidbody.drag = 1.0;
}
if (selectedId == GetInstanceID()) {
if (Input.GetKey (KeyCode.UpArrow)) transform.Translate (Vector3(0,0,1) * Time.deltaTime*speed);
if (Input.GetKey (KeyCode.DownArrow)) transform.Translate (Vector3(0,0,-1) * Time.deltaTime*speed);
if (Input.GetKey (KeyCode.Space)) transform.Translate (Vector3(0,1,0) * Time.deltaTime*speed);
if (Input.GetKey (KeyCode.LeftControl)) transform.Translate (Vector3(0,-1,0) * Time.deltaTime*speed);
if (Input.GetKey(KeyCode.RightArrow)) transform.Rotate(Vector3.up * speed * Time.deltaTime);
if (Input.GetKey(KeyCode.LeftArrow))
transform.Rotate(-Vector3.up * speed * Time.deltaTime);
}
}
function OnMouseDown () {
selectedId = GetInstanceID();
}
That really is all there is to it, then...
Thank you. I wanted to mix them together to get more workspace in my folders