Quantcast
Channel: Questions in topic: "dll"
Viewing all articles
Browse latest Browse all 706

(C# - working)(dll - not working) Object reference not set to an instance of an object

$
0
0
i have a project where i have to use a dll made from c# code. The scene has 3 object, 2 objects use script from the dll while the third object has a regular c# script. If you use the C# scripts instead of the dll everything in the scene works fine. scripts in the dll: car_2d: using System.Collections; using System.Collections.Generic; using UnityEngine; public class car_2d : MonoBehaviour { public float speed=0.0f; private float speed_max=10.0f; private float accel=5.0f; private float deccel; private float r1_speed=50.0f; private float r2_speed; //link to the input deput_control private deput_control deput_control_link_left_pad; private deput_control deput_control_link_right_pad; private string controller_output_left_pad; private string controller_output_right_pad; // Use this for initialization void OnEnable () { deccel=2*accel; r2_speed=2*r1_speed; //link to deput_control deput_control_link_left_pad=GameObject.Find("deput_left_pad").GetComponent(); deput_control_link_right_pad=GameObject.Find("deput_right_pad").GetComponent(); } // Update is called once per frame void Update () { //get output from deput controller_output_left_pad=deput_control_link_left_pad.deput_final_output; controller_output_right_pad=deput_control_link_right_pad.deput_final_output; //if press turn (left or right) then turn car if(Input.GetAxis("Horizontal")>0 || controller_output_right_pad=="right"){ transform.Rotate(Vector3.up*r1_speed*Time.deltaTime); } if(Input.GetAxis("Horizontal")<0 || controller_output_right_pad=="left"){ transform.Rotate(Vector3.up*-r1_speed* Time.deltaTime); } if(Input.GetAxis("Vertical")>0 || deput_control_link_left_pad.deput_active==true){ //if above max speed reach then stay at max speed+=accel*Time.deltaTime; if(speed>speed_max){ speed=speed_max; } }else{ if(speed>0){ speed-=deccel*Time.deltaTime; } if(speed<0){ speed=0.0f; } } //move car transform.Translate(Vector3.forward*speed*Time.deltaTime); } } car_manager: using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; public class car_manager : MonoBehaviour { //link to deputs private deput_control left_pad_link; private deput_control right_pad_link; private deput_control home_pad_link; //link to shapesboy_manager private shapesboy_manager shapesboy_manager_link; private bool system_menu_status_last=false; //link to objects/ scripts private car_2d player_car_script; private GameObject speed_meter; void configure_pads(){ left_pad_link.deput_setup("2way_v", 0, 0); right_pad_link.deput_setup("2way_h", 0, 0); home_pad_link.deput_setup("0way", 0, 0); } // Use this for initialization //void Start () { void OnEnable () { //link to shapesboy_manager shapesboy_manager_link=GameObject.Find("brain").GetComponent(); //link to deputs needed left_pad_link=GameObject.Find("deput_left_pad").GetComponent(); right_pad_link=GameObject.Find("deput_right_pad").GetComponent(); home_pad_link=GameObject.Find("deput_home_pad").GetComponent(); //link to objects/ scripts player_car_script=GameObject.Find("player_car").GetComponent(); speed_meter=GameObject.Find("speed_value"); //configure deput pads configure_pads(); } // Update is called once per frame void Update () { //get speed from car and post it on speed meter speed_meter.GetComponent().text=player_car_script.speed.ToString("F1"); } } the console gives the following errors: NullReferenceException: Object reference not set to an instance of an object car_manager.configure_pads () car_manager.OnEnable () and NullReferenceException: Object reference not set to an instance of an object car_2d.Update () i think after changing to a dll from C# that i can not "Find" the game object or GetComponent. For reference when i dont use the dll and use the C# scripts directly it works fine. Any help or direction is appreciated.

Viewing all articles
Browse latest Browse all 706

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>