Hello Unity3D,
I have a question about objects. How can i throw a prefab object?
For example: whenever i throw a particle prefab it throws just fine but whenever i throw a ball or a stick the prefab appears but it goes nowhere. Why is it that i can only throw a prefab particle and not a prefab game-object? If anyone knows how i can throw a prefab game-object.
Can you please tell me how?
Note: code below is not C# but JS-like, now obsolete, Unity Script
var rocket : GameObject; //our prefab
var throwPower : float = 10; //power variable determines how fast this object will be "shot out"variable
var reloadTime = 10; //time to reload
var timeBetweenShots = 10.0;
private var nextFire : float = 0.0;
private var timestamp = -10.0;
function Update()
{
if (Input.GetKeyDown("1") && Time.time > nextFire)
{
if (Time.time > timestamp + timeBetweenShots)
{
Debug.Log("I'm firing now");
timestamp = Time.time;
Switch();
}
}
}
function Switch()
{
yield WaitForSeconds(1);
clone = Instantiate(rocket, transform.position, transform.rotation); //the clone variable holds our instantiate action
clone.velocity = transform.TransformDirection(Vector3.forward * throwPower); //applies force to our prefab using the "forward" position times our throwPower variable
}