stupid problem

he everybody,

i know that this is a very little problem, but could you help me??

i get this error :
Assets/scripts/shoot.cs(17,50): error CS1502: The best overloaded method match for `UnityEngine.Object.Instantiate(UnityEngine.Object, UnityEngine.Vector3, UnityEngine.Quaternion)’ has some invalid arguments

with this script:

using UnityEngine;
using System.Collections;

public class shoot : MonoBehaviour {
	
	public int max, min, reload;
	public int grenades;
	public int trowspeed, shootspeed;
	
	public Transform spawnpoint;
	public Transform bullet;
	public Transform grenade;
	
	void Update () {
		if(Input.GetMouseButtonDown(2)){
			if(min > 0){
				Rigidbody fire = Instantiate(bullet , spawnpoint, Quaternion.identity)as Rigidbody;
				fire.rigidbody.AddForce(transform.forward * shootspeed);
				min --;
			}
		}
	}
}

please help me!!!

Rigidbody fire = Instantiate(bullet , spawnpoint.position, Quaternion.identity)as Rigidbody;

thanx it is fixed

same code other error :

NullReferenceException: Object reference not set to an instance of an object
shoot.Update () (at Assets/scripts/shoot.cs:17)

Hmm , the only other thing i can see that looks wrong is that you have created a variable of type Rigidbody fire … but than yer trying to access fire’s rigidbody , but it IS a rigidbody.

It might also jsut be a case of that you didnt assign the prefab in the editor ?

Your bullet needs to be a GameObject not a Transform

i tried all ready your move headingwest, but it give the same error

the prefab is asinged to in the editor.

it’s is the same error

Rigidbody fire = Instantiate(bullet , spawnpoint, Quaternion.identity)as Rigidbody;

The syntax should be :

static function Instantiate (original : Object, position : Vector3, rotation : Quaternion) : Object

and in your script :

public Transform spawnpoint;

Transform != Vector3
It needs to be spawnpoint.position

You should allways look at the error Unity shows you in the console window.
In this case i’m sure it would show an overload error and that there was a problem with the second member.

He already got that one , i told him that above , he has a new one now i thinks

using UnityEngine;
using System.Collections;

public class shoot : MonoBehaviour {
	
	public int max, min, reload;
	public int grenades;
	public int trowspeed, shootspeed;
	
	public GameObject bullet;
	public Transform grenade;

	void Update () {
		if(Input.GetMouseButtonDown(0)){
			if(min > 0){
				Rigidbody fire = Instantiate(bullet , transform.position, Quaternion.identity)as Rigidbody;
				fire.AddForce(Vector3.forward * shootspeed);
				min--;
			}
		}
	}
}

i am thinking or it would work
i am not really sure any more

fun :stuck_out_tongue:

i placed the script on the spawnpoint so i got one error fixed

hmmm, maybe it’s best you post the current version of the script.
ah… while i post lol

I don’t see anything wrong with that last script.
If it gives a null reference then it’s the assignement that has a problem.
Make sure your bullet has a rigidbody and it’s assigned to the right slot in the inspector.

i did it , but it gives that error.
:shock::shock::shock::shock::shock::shock::shock::shock::shock::shock:

Try this one, it’s the most simple shooter script.
See if it works with it or not. Assign the prefab in the Bullet slot.

using UnityEngine;

public class Shooter : MonoBehaviour {
	
	public Transform Bullet;
	
	void Update () {
		if (Input.GetMouseButtonDown (0)) {
			Transform t = (Transform) Instantiate (Bullet, transform.position, Quaternion.identity);
			t.rigidbody.AddForce (Vector3.forward * 3000);
		}
	}
}

sorry but this won’t work

thanx for your help

i gonna try a other way

error:
InvalidCastException: Cannot cast from source type to destination type.
shoot.Update () (at Assets/scripts/shoot.cs:21)

script:

using UnityEngine;
using System.Collections;

public class shoot : MonoBehaviour {
	
	public int max, min, reload;
	public int grenades;
	public int trowspeed, shootspeed;
	
	public GameObject bullet;
	public Transform grenade;
	
	public GUIText ammo;
	
	private Rigidbody fire;

	void Update () {
		ammo.text = min + "/" + max;
		if(Input.GetMouseButtonDown(0)){
			if(min > 0){
				Rigidbody fire = (Rigidbody) Instantiate(bullet, transform.position, Quaternion.identity);
				fire.AddForce(transform.forward * shootspeed);
				min--;
			}
		}
	}
}

help!!!:frowning:

There are several problems :

Give your variables a capital start letter : bullet → Bullet.
The Bullet should also be a Transform type and not a GameObject
Try debugging your script.
Remove what you don’t need and see if you can find the problem.
You will keep running into these errors throughout the development of the game if you don’t understand why it’s happening.