Problem:
Only translates when “F” key is held.
Question:
How can I press once and have it continue moving?
Script:
var force : float = 20.0f;
var spawnDistance : float = 1.0f;
var gameObject : GameObject;
function Start() {
if(Input.GetKey(KeyCode.F)) {
GameObject.Instatiate(transform.position + spawnDistance * transform.forward, transform.rotation);
rigidbody.AddForce(transform.forward * force);
}
}
in your current form, line 9 should be : gameObject = Instantiate( REMOVED FOR COUGH COUGH REASONS ); but this variable name is a big no-no. Unity uses both these names as key words (gameObject and GameObject), even if you look at any Unity Scripting Reference for Instantiate or Create, they use the variable name 'go'. Basically, don't use any Unity keyword as a variable name. It's not hard to call it 'myGameObject' or simply 'go' as in the docs. EDIT : Note the spelling error in your Instantiate also. It is up to you to proofread your code and check for spelling and syntax errors
– AlucardJaya good name would be "awesomeGameObject"
– FattieIndeed! You have an awesome flair for naming conventions.
– AlucardJay