- Home /
Question by
LightningHawk2 · Nov 28, 2016 at 08:03 AM ·
c#scripting problemclassesassign-variable
How to assign GameObject used in a Custom Class?
Hello,
I am making a weapon switching script for my game. I have made a custom class here:
public class WeaponManager : MonoBehaviour
{
public string type;
public string name;
public float damage;
public float range;
public int perClip;
public int maxAmmo;
public float fireRate;
public float reloadTime;
public GameObject weapon; //weapon body
public Transform bulletSpawn;
public WeaponManager(string typ, string nam, float dmg, float rng, int pCl, int mxA, float frR, float rTm, GameObject wep, Transform blt)
{
type = typ;
name = nam;
damage = dmg;
range = rng;
perClip = pCl;
maxAmmo = mxA;
fireRate = frR;
reloadTime = rTm;
weapon = wep;
bulletSpawn = blt;
}
Now, I will create an object from this class.
WeaponManager M16 = new WeaponManager("Rifle", "M16", 20, 200, 30, 180, 10, 1.5f,
GetComponent<GameObject>, GetComponent<Transform>);
What I am trying to do when you see the
GetComponent<GameObject>()
stuff is to assign a tangible object in Unity3D. I am trying to assign the weapon's body GameObject and the weapon's bullet spawn Transform created in the WeaponManager class for each new weapon created using the class.
I can't figure out how to get the little bar in the Unity Editor screens to pop up to drag a prefab into it.
A thank you in advance for those willing to help!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612101457im_/https://answers.unity.com/themes/thub/images/avi.jpg)