Hello whoever might be reading this.
First off, i'd like to apologize for any bad grammar that might occur.
English is not my main Language.
So, my problem is so :
I got a script(lets call it scriptA), where i got a class inside of it(lets call it classA), that is attached to a gameobject.
and i got another script, at another gameobject(lets call this scriptB), and i am trying to assign a variable from script scriptA's classA to a variable in scriptB, on collision.
now, ive tried dozen of things, without luck. and the most common error it gives me is
"NullReferenceException: Object reference not set to an instance of an object
Equip.OnCollisionEnter (UnityEngine.Collision col) (at Assets/Player/SCRIPTS/Equip.cs:42)"
Any help would be insanely appreaciated.
**scriptA :**
using UnityEngine;
using System.Collections;
public class BEGINNERSWORD : MonoBehaviour {
static GameObject MODEL = Resources.Load("SWORD_MODEL", typeof(GameObject)) as GameObject;
public class BEGINNERSWORD_01 : WEAPONS {
void Init () {
_NAME = "Beginner Sword";
_TYPE = 1;
_VALUE = 001;
_MODEL = MODEL;
_ATTDMG = 10;
}
}
//public BEGINNERSWORD_01 BS_01 = new BEGINNERSWORD_01;
}
**scriptB:**
using UnityEngine;
using System.Collections;
public class Equip : MonoBehaviour {
public GameObject Weapon = null;
public Transform rHand;
bool equiped = false;
GameObject t = null;
// Use this for initialization
void Start () {
}
void equip(){
if(!equiped){
t = Instantiate (Weapon, rHand.position, rHand.rotation)as GameObject;
t.transform.parent = rHand.transform;
equiped = true;
}
else if (equiped){
Destroy((GameObject)t);
equiped = false;
}
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.E)){
if(Weapon = null){
Debug.Log("NoWeapon" + Weapon.tag);
}
else{
equip ();
}
}
}
public void OnCollisionEnter(Collision col){
if(col.gameObject.tag == "SWORD"){
BEGINNERSWORD bs = col.gameObject.GetComponent();
BEGINNERSWORD.BEGINNERSWORD_01 bs1 = GetComponent();
Weapon = bs1._MODEL;
}
}
}
↧