Extension method must be defined in a non-generic static class

I can’t figure out this problem I have.
Extension method must be defined in a non-generic static class

I have two Extensions WeaponBase and DamageBase. This problem is only occurring with DamageBase. Which makes it even more odd.

My editor is showing something is wrong with Damage
I’m able to control click DamageBase and it opens up DamageBase. So its finding the extension just fine.

public class Damage : DamageBase
{

}
    public class DamageBase : MonoBehaviour {
        public GameObject Effect;
        public float LifeTimeEffect = 3;
        [HideInInspector]
        public GameObject Owner;
        public int Layer = 0;
        public int Damage = 20;
        public string[] TargetTag;
        public string Tag;
    }

When you mention ‘extension’ you’re actually referring to inheritance, which has nothing to do with extension methods or the error.

Refer to the docs on what extension methods actually are: Extension Methods - C# | Microsoft Learn

Seeing as you’ve elected to post only part of the code I can’t help any more than what I’ve explained above.

1 Like

The “Extension” cited by your compile is not an “extension of some other class”, its about “Extension methods”, can you share the whole code? You probably have something like public static void MyExtensionMethod (this classToExtend) {} and this kind of extension can exist only on non-generic static class

1 Like

I really appreciate the two responses to this. Thanks guys.

Sorry I thought i showed all the necessary code.

I have a script named DamageBase.cs

using UnityEngine;
    public class DamageBase : MonoBehaviour {
        public GameObject Effect;
        public float LifeTimeEffect = 3;
        [HideInInspector]
        public GameObject Owner;
        public int Layer = 0;
        public int Damage = 20;
        public string[] TargetTag;
        public string Tag;
    }

Then I have a script called Damage.cs

using UnityEngine;

public struct DamagePackage{
    public int Damage;
    public GameObject Owner;
}
public class Damage : DamageBase
{
    public bool Explosive;
    public float ExplosionRadius = 20;
    public float ExplosionForce = 1000;
    public bool HitedActive = true;
    public bool UnlimitedActive = false;
    public float TimeActive = 0;
    public bool RandomTimeActive;
    private float timetemp = 0;
    public GameObject DestroyAfterObject;
    public float DestryAfterDuration = 10;
   
    private void Start()
    {
        switch(Tag){
        case "Faction 1":
            gameObject.layer = 21;
            gameObject.tag = "Faction 1";
                break;
        case "Faction 2":
            gameObject.layer = 22;
            gameObject.tag = "Faction 2";
            break;
        case "Faction 3":
            gameObject.layer = 23;
            gameObject.tag = "Faction 3";
            break;
        case "Faction 4":
            gameObject.layer = 24;
            gameObject.tag = "Faction 4";
            break;
        }
        timetemp = Time.time;
        if(RandomTimeActive)
            TimeActive = Random.Range(TimeActive/2f,TimeActive);
        if (!Owner || !Owner.GetComponent<Collider>()) return;
        Physics.IgnoreCollision(GetComponent<Collider> (), Owner.GetComponent<Collider>()); // calling GetComponet collider each bullet fire isnt efficient
    }
    private void Update()
    {
        if (UnlimitedActive) { // keeps time active unlimited by reseting TimeActive over 0 on each update
            TimeActive = 100;
        }
        if(TimeActive>0){
            if(Time.time >= (timetemp + TimeActive)){
                Active();
            }
        }
    }
    public void Active()
    {
        if (!UnlimitedActive) {
            if (Effect)
            {
                GameObject obj = (GameObject) Instantiate(Effect, transform.position, transform.rotation);
                Destroy(obj, LifeTimeEffect);
            }
            if (Explosive)
                ExplosionDamage();
            if(DestroyAfterObject){
                DestroyAfterObject.transform.parent = null;
                if(DestroyAfterObject.GetComponent<ParticleSystem>())
                    //DestroyAfterObject.GetComponent<ParticleSystem>().emission = 0; // this was depreciated so replaced it with the line below and created the function SetEmissionRate
                    SetEmissionRate(DestroyAfterObject.GetComponent<ParticleSystem>(),0);
               
                Destroy(DestroyAfterObject,DestryAfterDuration);
            }
               
                Destroy (gameObject);
        }
    }
    private void ExplosionDamage()
    {
        Collider[] hitColliders = Physics.OverlapSphere(transform.position, ExplosionRadius);
        for (int i = 0; i < hitColliders.Length; i++)
        {
            Collider hit = hitColliders[i];
            if (!hit){
                continue;
            }
           
            DamagePackage dm = new DamagePackage();
            dm.Damage = Damage;
            dm.Owner = Owner;
                                int EnemyShieldLayerName = Tag == "Faction 1" ? 17: 16;
            if(hit.gameObject.layer == EnemyShieldLayerName){ // no idea what the point of this is
                Collider ParentGameObject = hit.transform.root.GetComponent<Collider> ();
                ParentGameObject.gameObject.SendMessage("ApplyDamage",dm,SendMessageOptions.DontRequireReceiver);
            }else{
                hit.gameObject.SendMessage("ApplyDamage",dm,SendMessageOptions.DontRequireReceiver);
            }
            if (hit.GetComponent<Rigidbody>()){
                hit.GetComponent<Rigidbody>().AddExplosionForce(ExplosionForce, transform.position, ExplosionRadius, 3.0f);
            }
        }
    }
    private void NormalDamage(Collider collider)    {
        DamagePackage dm = new DamagePackage();
        dm.Damage = Damage;
        dm.Owner = Owner;
        collider.gameObject.SendMessage("ApplyDamage",dm,SendMessageOptions.DontRequireReceiver);
    }
   
    private void OnCollisionEnter(Collision collision){
        GameObject ObjectThatsHit = collision.gameObject;
       
        if (HitedActive) {
            string collsionTag = collision.gameObject.tag;
            if (collsionTag != "Particle" && ObjectThatsHit.tag != this.gameObject.tag) {
               
                if (!Explosive){ 
                    int EnemyShieldLayerName = Tag == "Faction 1" ? 17: 16;
                    if(collision.gameObject.layer == EnemyShieldLayerName){ // no idea what the point of this is
                        Collider ParentGameObject = collision.collider.transform.root.GetComponent<Collider> ();
                        NormalDamage (ParentGameObject);
                    }else{
                        NormalDamage (collision.collider);
                    }
                }
                Active ();
                if (ObjectThatsHit.tag == "Exploder") {
                    ExplodeObject (ObjectThatsHit);
                }
               
            }
        }
       
    }
   
  
   
}

Before posting my issue i read all about static extensions. Idk what this is i guess idk. This is some others guy code.
Seems like it extends the monobehaviour class. Like having the DamageBase component attached with out actually really attaching it? idk

So is there more code you haven’t copied?

Because you have methods such as ExplodeObject or SetEmmissionRate that aren’t defined anywhere in this code. When I comment out these lines I get no errors.

Again, refer to the docs I linked about what an extension method is.

Are you getting more than one error? Is it possible this error isn’t related to this particular class? The error should tell you exactly where the error lies.

Also you might want to properly format and space your code out. It’s nigh unreadable.

2 Likes

The errors do not seem to be coming from this snippet, can you share a print of the error on console?

1 Like

Copying code you don’t understand is not going to get you far.

Every component extends Monobehaviour. It’s nothing novel.

How much coding experience/understanding do you have?

1 Like

lol

ya i removed two methods to help shorten the code

using UnityEngine;
public struct DamagePackage{
    public int Damage;
    public GameObject Owner;
}
public class Damage : DamageBase
{
    public bool Explosive;
    public float ExplosionRadius = 20;
    public float ExplosionForce = 1000;
    public bool HitedActive = true;
    public bool UnlimitedActive = false;
    public float TimeActive = 0;
    public bool RandomTimeActive;
    private float timetemp = 0;
    public GameObject DestroyAfterObject;
    public float DestryAfterDuration = 10;
   
    private void Start()
    {
        switch(Tag){
        case "Faction 1":
            gameObject.layer = 21;
            gameObject.tag = "Faction 1";
                break;
        case "Faction 2":
            gameObject.layer = 22;
            gameObject.tag = "Faction 2";
            break;
        case "Faction 3":
            gameObject.layer = 23;
            gameObject.tag = "Faction 3";
            break;
        case "Faction 4":
            gameObject.layer = 24;
            gameObject.tag = "Faction 4";
            break;
        }
        timetemp = Time.time;
        if(RandomTimeActive)
            TimeActive = Random.Range(TimeActive/2f,TimeActive);
        if (!Owner || !Owner.GetComponent<Collider>()) return;
        Physics.IgnoreCollision(GetComponent<Collider> (), Owner.GetComponent<Collider>()); // calling GetComponet collider each bullet fire isnt efficient
    }
    private void Update()
    {
        if (UnlimitedActive) { // keeps time active unlimited by reseting TimeActive over 0 on each update
            TimeActive = 100;
        }
        if(TimeActive>0){
            if(Time.time >= (timetemp + TimeActive)){
                Active();
            }
        }
    }
    public void Active()
    {
        if (!UnlimitedActive) {
            if (Effect)
            {
                GameObject obj = (GameObject) Instantiate(Effect, transform.position, transform.rotation);
                Destroy(obj, LifeTimeEffect);
            }
            if (Explosive)
                ExplosionDamage();
            if(DestroyAfterObject){
                DestroyAfterObject.transform.parent = null;
                if(DestroyAfterObject.GetComponent<ParticleSystem>())
                    //DestroyAfterObject.GetComponent<ParticleSystem>().emission = 0; // this was depreciated so replaced it with the line below and created the function SetEmissionRate
                    SetEmissionRate(DestroyAfterObject.GetComponent<ParticleSystem>(),0);
               
                Destroy(DestroyAfterObject,DestryAfterDuration);
            }
               
                Destroy (gameObject);
        }
    }
    private void ExplosionDamage()
    {
        Collider[] hitColliders = Physics.OverlapSphere(transform.position, ExplosionRadius);
        for (int i = 0; i < hitColliders.Length; i++)
        {
            Collider hit = hitColliders[i];
            if (!hit){
                continue;
            }
           
            DamagePackage dm = new DamagePackage();
            dm.Damage = Damage;
            dm.Owner = Owner;
                                int EnemyShieldLayerName = Tag == "Faction 1" ? 17: 16;
            if(hit.gameObject.layer == EnemyShieldLayerName){ // no idea what the point of this is
                Collider ParentGameObject = hit.transform.root.GetComponent<Collider> ();
                ParentGameObject.gameObject.SendMessage("ApplyDamage",dm,SendMessageOptions.DontRequireReceiver);
            }else{
                hit.gameObject.SendMessage("ApplyDamage",dm,SendMessageOptions.DontRequireReceiver);
            }
            if (hit.GetComponent<Rigidbody>()){
                hit.GetComponent<Rigidbody>().AddExplosionForce(ExplosionForce, transform.position, ExplosionRadius, 3.0f);
            }
        }
    }
    private void NormalDamage(Collider collider)    {
        DamagePackage dm = new DamagePackage();
        dm.Damage = Damage;
        dm.Owner = Owner;
        collider.gameObject.SendMessage("ApplyDamage",dm,SendMessageOptions.DontRequireReceiver);
    }
   
    private void OnCollisionEnter(Collision collision){
        GameObject ObjectThatsHit = collision.gameObject;
       
        if (HitedActive) {
            string collsionTag = collision.gameObject.tag;
            if (collsionTag != "Particle" && ObjectThatsHit.tag != this.gameObject.tag) {
               
                if (!Explosive){ 
                    int EnemyShieldLayerName = Tag == "Faction 1" ? 17: 16;
                    if(collision.gameObject.layer == EnemyShieldLayerName){ // no idea what the point of this is
                        Collider ParentGameObject = collision.collider.transform.root.GetComponent<Collider> ();
                        NormalDamage (ParentGameObject);
                    }else{
                        NormalDamage (collision.collider);
                    }
                }
                Active ();
                if (ObjectThatsHit.tag == "Exploder") {
                    ExplodeObject (ObjectThatsHit);
                }
               
            }
        }
       
    }
   
    private void ExplodeObject(GameObject obj)
    {
        //ExploderObject ExploderGameObject = PlanetSettings.ExploderGameObject;
        // activate exploder
        //ExploderUtils.SetActive(ExploderGameObject.gameObject, true);
       
        // move exploder object to the same position
        //ExploderGameObject.transform.position = ExploderUtils.GetCentroid(obj);
        //ExploderGameObject.Explode();
       
    }
    // Function made by John Steuber
    void SetEmissionRate(this ParticleSystem particleSystem, float emissionRate){
       //var emission = particleSystem.emission;
       //var rate = emission.rate;
       //rate.constantMax = emissionRate;
        //emission.rate = rate;
   }
   
}

Oh look there’s your problem in the code you for some reason decided not to include. Remember when I said “because you didn’t include all the code we can’t help you?” Hmm?

Read about extension methods again, and tell me what’s wrong with that last method.

2 Likes

12 years coding experience. Fluent in php.

I’m not coping someone’s code. Its a asset I use that depreciated that im trying to fix.

This is everything in the console.

Assets\AirStrike\Scripts\WeaponSystem\Damage.cs(11,14): error CS1106: Extension method must be defined in a non-generic static class

I realize my method doesn’t follow the syntax of the link you posted with the static extensions.

I have another example of this working. With WeaponBase.
I dont know why it works with WeaponBase but not DamageBase

Unless After I fix DamageBase then the same error will pop up for WeaponBase idk.
As if the compiler i stuck on this error first.

So why are you surprised you have an error???

1 Like

Cause no error is showing for WeaponBase being used the exact way

For gods sake.

This:

void SetEmissionRate(this ParticleSystem particleSystem, float emissionRate)

Is invalid code. this denotes an extension method. Extension methods can only be in static classes and must be static themselves.

Understand the problem?

See this is WeaponBase.cs

using UnityEngine;
    public class WeaponBase : MonoBehaviour {
        [HideInInspector]
        public GameObject Owner;
        [HideInInspector]
        public int Layer;
        [HideInInspector]
        public GameObject Target;
        [HideInInspector]
        public string[] TargetTag;
        public bool RigidbodyProjectile;
        public Vector3 TorqueSpeedAxis;
        public GameObject TorqueObject;
    }

Here is WeaponLauncher.cs using WeaponBase and there are 3 other scripts using it to no issues.

using UnityEngine;
using Random = UnityEngine.Random;
[RequireComponent(typeof(AudioSource))]
public class WeaponLauncher : WeaponBase
{
    public int Faction;
    public bool OnActive;
    public Texture2D Icon;
    public Transform[] MissileOuter;
    public GameObject Missile;
    public float FireRate = 0.1f;
    public float Spread = 1;
    public float ForceShoot = 8000;
    public bool NoShotCycle;
    public int NumBullet = 1;
    public int Ammo = 10;
    public int AmmoMax = 10;
    public bool InfinityAmmo = false;
    public float ReloadTime = 1;
    public bool ShowHUD = true;
    public int MaxAimRange = 10000;
    public bool ShowCrosshair;
    public Texture2D CrosshairTexture;
    public Texture2D TargetLockOnTexture;
    public Texture2D TargetLockedTexture;
    public float DistanceLock = 200;
    public float TimeToLock = 2;
    public float AimDirection = 0.8f;
    public bool Seeker;
    public GameObject Shell;
    public float ShellLifeTime = 4;
    public Transform[] ShellOuter;
    public int ShellOutForce = 300;
    public GameObject Muzzle;
    public float MuzzleLifeTime = 2;
    public AudioClip[] SoundGun;
    public AudioClip SoundReloading;
    public AudioClip SoundReloaded;
    private float timetolockcount = 0;
    private float nextFireTime = 0;
    private GameObject target;
    private Vector3 torqueTemp;
    private float reloadTimeTemp;
    private AudioSource audioSource;
    [HideInInspector]
    public bool Reloading;
    [HideInInspector]
    public float ReloadingProcess;
    string MissileName;
    string TagName;
    int LayerNumber;
    //string[] TargetTag;
    private void Start ()    {
        TagName = Faction == 1 ? "Faction 1" : "Faction 2";
        LayerNumber = Faction == 1 ?  21 : 22;
       
        if (!Owner) 
            Owner = this.transform.root.gameObject; // this prevents bullets from hitting the ship the weapon is shooting from
       
        if (!audioSource) {
            audioSource = this.GetComponent<AudioSource> ();
            if (!audioSource) {
                this.gameObject.AddComponent<AudioSource> ();   
            }
        }
        MissileName = Missile.name.ToString();
       
    }
    [HideInInspector]
    public Vector3 AimPoint;
    [HideInInspector]
    public GameObject AimObject;
    private void rayAiming ()
    {
        RaycastHit hit;
        if (Physics.Raycast (transform.position, this.transform.forward, out hit, MaxAimRange)) {
            if (Missile != null && hit.collider.tag != Missile.tag) {
                AimPoint = hit.point;
                AimObject = hit.collider.gameObject;
            }
        } else {
            AimPoint = this.transform.position + (this.transform.forward * MaxAimRange);
            AimObject = null;
        }
       
    }
   
    void FixedUpdate ()
    {
        if (OnActive) {
            rayAiming ();
        }
    }
   
    private void Update ()
    {
        if(CurrentCamera == null){
           
            CurrentCamera = Camera.main;
           
            if(CurrentCamera == null)
                CurrentCamera = Camera.current;
        }
        if(Camera.current!=null){
            if(CurrentCamera != Camera.current){
                CurrentCamera = Camera.current;
            }
        }
       
       
        if (OnActive) {
            if (TorqueObject) {
                TorqueObject.transform.Rotate (torqueTemp * Time.deltaTime);
                torqueTemp = Vector3.Lerp (torqueTemp, Vector3.zero, Time.deltaTime);
            }
            if (Seeker) {
           
                for (int t=0; t<TargetTag.Length; t++) {
                    if (GameObject.FindGameObjectsWithTag (TargetTag [t]).Length > 0) {
                        GameObject[] objs = GameObject.FindGameObjectsWithTag (TargetTag [t]);
                        float distance = int.MaxValue;
                       
                        if (AimObject != null && AimObject.tag == TargetTag [t]) {
                            float dis = Vector3.Distance (AimObject.transform.position, transform.position);
                            if (DistanceLock > dis) {
                                if (distance > dis) {
                                    if (timetolockcount + TimeToLock < Time.time) {   
                                        distance = dis;
                                        target = AimObject;
                                    }
                                }
                            }   
                        } else {
                            for (int i = 0; i < objs.Length; i++) {
                                if (objs [i]) {
                                    Vector3 dir = (objs [i].transform.position - transform.position).normalized;
                                    float direction = Vector3.Dot (dir, transform.forward);
                                    float dis = Vector3.Distance (objs [i].transform.position, transform.position);
                                    if (direction >= AimDirection) {
                                        if (DistanceLock > dis) {
                                            if (distance > dis) {
                                                if (timetolockcount + TimeToLock < Time.time) {   
                                                    distance = dis;
                                                    target = objs [i];
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (target) {
                float targetdistance = Vector3.Distance (transform.position, target.transform.position);
                Vector3 dir = (target.transform.position - transform.position).normalized;
                float direction = Vector3.Dot (dir, transform.forward);
                if (targetdistance > DistanceLock || direction <= AimDirection) {
                    Unlock ();
                }
            }
       
            if (Reloading) {
                ReloadingProcess = ((1 / ReloadTime) * (reloadTimeTemp + ReloadTime - Time.time));
                if (Time.time >= reloadTimeTemp + ReloadTime) {
                    Reloading = false;
                    if (SoundReloaded) {
                        if (audioSource) {
                            audioSource.PlayOneShot (SoundReloaded);
                        }
                    }
                    Ammo = AmmoMax;
                }
            } else {
                if (Ammo <= 0) {
                    Unlock ();
                    Reloading = true;
                    reloadTimeTemp = Time.time;
               
                    if (SoundReloading) {
                        if (audioSource) {
                            audioSource.PlayOneShot (SoundReloading);
                        }
                    }
                }
            }
        }
    }
    public Camera CurrentCamera;
    private void DrawTargetLockon (Transform aimtarget, bool locked)
    {
        if (!ShowHUD)
            return;
       
        if (CurrentCamera) {
            Vector3 dir = (aimtarget.position - CurrentCamera.transform.position).normalized;
            float direction = Vector3.Dot (dir, CurrentCamera.transform.forward);
            if (direction > 0.5f) {
                Vector3 screenPos = CurrentCamera.WorldToScreenPoint (aimtarget.transform.position);
                float distance = Vector3.Distance (transform.position, aimtarget.transform.position);
                if (locked) {
                    if (TargetLockedTexture)
                        GUI.DrawTexture (new Rect (screenPos.x - (TargetLockedTexture.width / 2), Screen.height - screenPos.y - (TargetLockedTexture.height / 2), TargetLockedTexture.width, TargetLockedTexture.height), TargetLockedTexture);
                    GUI.Label (new Rect (screenPos.x + 40, Screen.height - screenPos.y, 200, 30), aimtarget.name + " " + Mathf.Floor (distance) + "m.");
                } else {
                    if (TargetLockOnTexture)
                        GUI.DrawTexture (new Rect (screenPos.x - TargetLockOnTexture.width / 2, Screen.height - screenPos.y - TargetLockOnTexture.height / 2, TargetLockOnTexture.width, TargetLockOnTexture.height), TargetLockOnTexture);
                }
               
               
            }
        } else {
            //Debug.Log("Can't Find camera");
        }
    }
    private Vector3 crosshairPos;
    private void DrawCrosshair ()
    {
        if(!ShowCrosshair)
            return;
       
        if (CurrentCamera) {
            Vector3 screenPosAim = CurrentCamera.WorldToScreenPoint (AimPoint);
            crosshairPos += ((screenPosAim - crosshairPos) / 5);
            if (CrosshairTexture) {
                GUI.DrawTexture (new Rect (crosshairPos.x - CrosshairTexture.width / 2, Screen.height - crosshairPos.y - CrosshairTexture.height / 2, CrosshairTexture.width, CrosshairTexture.height), CrosshairTexture);
               
            }
        }
    }
    private void OnGUI ()
    {
        if (OnActive) {
            if (Seeker) {
           
                if (target) {
                    DrawTargetLockon (target.transform, true);
                }
               
                for (int t=0; t<TargetTag.Length; t++) {
                    if (GameObject.FindGameObjectsWithTag (TargetTag [t]).Length > 0) {
                        GameObject[] objs = GameObject.FindGameObjectsWithTag (TargetTag [t]);
                        for (int i = 0; i < objs.Length; i++) {
                            if (objs [i]) {
                                Vector3 dir = (objs [i].transform.position - transform.position).normalized;
                                float direction = Vector3.Dot (dir, transform.forward);
                                if (direction >= AimDirection) {
                                    float dis = Vector3.Distance (objs [i].transform.position, transform.position);
                                    if (DistanceLock > dis) {
                                        DrawTargetLockon (objs [i].transform, false);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            DrawCrosshair ();
        }
       
    }
    private void Unlock ()
    {
        timetolockcount = Time.time;
        target = null;
    }
   
    private int currentOuter = 0;
    public bool Shoot ()
    {
        bool successfulShot = false;
        if (InfinityAmmo) {
            Ammo = 1;   
        }
        if (!NoShotCycle) {
                if (Ammo > 0) {
               
                    if (Time.time > nextFireTime + FireRate) {
                        nextFireTime = Time.time;
                        torqueTemp = TorqueSpeedAxis;
                        Ammo -= 1;
                        Vector3 missileposition = this.transform.position;
                        Quaternion missilerotate = this.transform.rotation;
                        if (MissileOuter.Length > 0) {
                            missilerotate = MissileOuter [currentOuter].transform.rotation;   
                            missileposition = MissileOuter [currentOuter].transform.position;   
                        }
                        if (MissileOuter.Length > 0) {
                            currentOuter += 1;
                            if (currentOuter >= MissileOuter.Length)
                                currentOuter = 0;
                        }
               
                        if (Muzzle) {
                            GameObject muzzle = (GameObject)GameObject.Instantiate (Muzzle, missileposition, missilerotate);
                            muzzle.transform.parent = this.transform;
                            GameObject.Destroy (muzzle, MuzzleLifeTime);
                            if (MissileOuter.Length > 0) {
                                muzzle.transform.parent = MissileOuter [currentOuter].transform;
                            }
                        }
               
                        for (int i = 0; i < NumBullet; i++) {
                            if (Missile) {
                                Vector3 spread = new Vector3 (Random.Range (-Spread, Spread), Random.Range (-Spread, Spread), Random.Range (-Spread, Spread)) / 100;
                                Vector3 direction = this.transform.forward + spread;
                       
                                GameObject bullet = PhotonNetwork.Instantiate (MissileName, missileposition, missilerotate,0);
                                DamageBase damangeBase = bullet.GetComponent<DamageBase> ();
                           
                                if (damangeBase) {
                               
                                    damangeBase.Owner = Owner;
                                    damangeBase.TargetTag = TargetTag;
                                    damangeBase.Layer = LayerNumber;
                                    damangeBase.Tag = TagName;
                                }
                                WeaponBase weaponBase = bullet.GetComponent<WeaponBase> ();
                                if (weaponBase) {
                                    weaponBase.Owner = Owner;
                                    weaponBase.Target = target;
                                    weaponBase.Layer = LayerNumber;
                                    weaponBase.TargetTag = TargetTag;
                               
                                }
                                bullet.transform.forward = direction;
                                if (RigidbodyProjectile) {
                                    if (bullet.GetComponent<Rigidbody> ()) {
                                        if (Owner != null && Owner.GetComponent<Rigidbody> ()) {
                                            bullet.GetComponent<Rigidbody> ().velocity = Owner.GetComponent<Rigidbody> ().velocity;
                                        }
                                        bullet.GetComponent<Rigidbody> ().AddForce (direction * ForceShoot);   
                                    }
                                }
                       
                            }
                        }
                        if (Shell) {
                            Transform shelloutpos = this.transform;
                            if (ShellOuter.Length > 0) {
                                shelloutpos = ShellOuter [currentOuter];
                            }
                   
                            GameObject shell = (GameObject)Instantiate (Shell, shelloutpos.position, Random.rotation);
                            GameObject.Destroy (shell.gameObject, ShellLifeTime);
                            if (shell.GetComponent<Rigidbody> ()) {
                                shell.GetComponent<Rigidbody> ().AddForce (shelloutpos.forward * ShellOutForce);
                            }
                        }
                   
                        if (SoundGun.Length > 0) {
                            if (audioSource) {
                                audioSource.PlayOneShot (SoundGun [Random.Range (0, SoundGun.Length)]);
                            }
                        }
               
                        nextFireTime += FireRate;
                    }
                } 
        } else {
            if (Ammo > 0) {
                if (Time.time > nextFireTime + FireRate) {
                    successfulShot = true;
                    int MissileAmount = MissileOuter.Length;
                    nextFireTime = Time.time;
                    torqueTemp = TorqueSpeedAxis;
                    Ammo -= 1;
                    for (int i = 0; i < MissileAmount; i++) {
                    Vector3 missileposition = this.transform.position;
                    Quaternion missilerotate = this.transform.rotation;
                    if (MissileOuter.Length > 0) {
                        missilerotate = MissileOuter [currentOuter].transform.rotation;   
                        missileposition = MissileOuter [currentOuter].transform.position;   
                    }
                   
                    if (MissileOuter.Length > 0) {
                        currentOuter += 1;
                        if (currentOuter >= MissileOuter.Length)
                            currentOuter = 0;
                    }
                   
                    if (Muzzle) {
                        GameObject muzzle = (GameObject)GameObject.Instantiate (Muzzle, missileposition, missilerotate);
                        muzzle.transform.parent = this.transform;
                        GameObject.Destroy (muzzle, MuzzleLifeTime);
                        if (MissileOuter.Length > 0) {
                            muzzle.transform.parent = MissileOuter [currentOuter].transform;
                        }
                    }
                   
                   
                        if (Missile) {
                            Vector3 spread = new Vector3 (Random.Range (-Spread, Spread), Random.Range (-Spread, Spread), Random.Range (-Spread, Spread)) / 100;
                            Vector3 direction = this.transform.forward + spread;
                                                       
                            GameObject bullet = PhotonNetwork.Instantiate (MissileName, missileposition, missilerotate,0);
                           
                            DamageBase damangeBase = bullet.GetComponent<DamageBase> ();
                           
                            if (damangeBase) {
                               
                                damangeBase.Owner = Owner;
                                damangeBase.TargetTag = TargetTag;
                                damangeBase.Layer = LayerNumber;
                                damangeBase.Tag = TagName;
                            }
                            WeaponBase weaponBase = bullet.GetComponent<WeaponBase> ();
                            if (weaponBase) {
                                weaponBase.Owner = Owner;
                                weaponBase.Target = target;
                                weaponBase.Layer = LayerNumber;
                                weaponBase.TargetTag = TargetTag;
                            }
                            bullet.transform.forward = direction;
                            if (RigidbodyProjectile) {
                                if (bullet.GetComponent<Rigidbody> ()) {
                                    if (Owner != null && Owner.GetComponent<Rigidbody> ()) {
                                        bullet.GetComponent<Rigidbody> ().velocity = Owner.GetComponent<Rigidbody> ().velocity;
                                    }
                                   
                                    bullet.GetComponent<Rigidbody> ().AddForce (direction * ForceShoot);
                                   
                                }
                            }
                           
                        }
                       
                    }
                   
                    if (Shell) {
                        Transform shelloutpos = this.transform;
                        if (ShellOuter.Length > 0) {
                            shelloutpos = ShellOuter [currentOuter];
                        }
                       
                        GameObject shell = (GameObject)Instantiate (Shell, shelloutpos.position, Random.rotation);
                        GameObject.Destroy (shell.gameObject, ShellLifeTime);
                        if (shell.GetComponent<Rigidbody> ()) {
                            shell.GetComponent<Rigidbody> ().AddForce (shelloutpos.forward * ShellOutForce);
                        }
                    }
                   
                    if (SoundGun.Length > 0) {
                        if (audioSource) {
                            audioSource.PlayOneShot (SoundGun [Random.Range (0, SoundGun.Length)]);
                        }
                    }
                   
                    nextFireTime += FireRate;
                }
            } 
        }
        return successfulShot;   
    }
}

ahh good catch, thanks man
Ya i did read on google that using this would cause this error. I guess i should of did a scan for the word this insead of just eyed it.

I wanted to call you a dick but honestly cause I didn’t give all the code and it was due to that lol. I honestly deserve the harshness. :slight_smile:

Thanks for kicking me in the face. It was needed.

This is an extended method in code.

void SetEmissionRate(this ParticleSystem particleSystem, float emissionRate) { }
  • The extended method requires a static class, hence the error message.

  • And you can’t make a static class because it inherits from MonoBehaviour.

Edit:
Too late to answer like Internet Explorer.

1 Like

Mate, he said nothing wrong, what has hurt your feelings? He asked about your experience maybe, you made a sequence of silly errors that gave this impression, posting code from screenshots, deciding which is and which isnt important hiding some code two times, asking before at least a small research - if you copy and paste your error on google the first result will explain what is an extension…- this is the kind of error that novice do

1 Like