- Home /
Question by
superstar123 · Jul 18, 2011 at 09:12 AM ·
javascriptrigidbodyinstantiatemouse
Increase enegy before shooting
I want the player can create the sphere when he press the right mouse and when I release, the player shoot. Here is my script:
var BulletBossSuper : GameObject;
function Update () {
Shoot();
}
function Shoot()
{
if (Input.GetMouseButtonDown (1))
{
var clone = Instantiate (BulletBossSuper, transform.position,
Quaternion.identity);
}
if (Input.GetMouseButtonUp (1))
{
clone.rigidbody.AddForce(transform.forward*1000);
//Report at this line : "Object reference not set to an instance of an object"
} }
How can I make this script work
Regards
Comment
Best Answer
Answer by YikYikHeiHei · Jul 19, 2011 at 01:00 AM
I think you want to this...
var BulletBossSuper : Rigidbody;
var clone;
function Update ()
{
Shoot();
}
function Shoot()
{
if (Input.GetMouseButtonDown (1))
{
clone = Instantiate (BulletBossSuper, transform.position,Quaternion.identity);
clone.rigidbody.Sleep();
}
if (Input.GetMouseButtonUp (1))
{
clone.rigidbody.WakeUp();
clone.rigidbody.AddForce(transform.forward*1000);
}
}
Thank you, it works, and I can learn a lot from this script :)
Your answer
![](https://koobas.hobune.stream/wayback/20220612150003im_/https://answers.unity.com/themes/thub/images/avi.jpg)