Jump to content
Unity Insider Forum

C# NullPointerReference????


LordChanka
 Share

Recommended Posts

Mein Script wirft NullReferenceException aber wieso? Bitte hier um Hilfe ^^

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

//diese Klasse wird an den Body angehäftet
public class TEST : MonoBehaviour
{
    public Stats p = new Stats();
    Task t = new Task();
    void Start() { p.LEBEN = 1; } // hier kann geschrieben werden
    void Update()
    {
        print(p.LEBEN); // ausgabe 1 (so wie gewollt)
        t.PRINTER();
    }
    public void write(int wert) { p.LEBEN = wert; } // hier kann scheinbar nicht mehr geschrieben werden
}

-------------------------------------------------------------------------------------------------------------------------------------

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

//Extra Datei

public class Task : MonoBehaviour
{

    TEST c;
    void Start() { c = new TEST(); }
    public void PRINTER() { c.write(666); }

}

-------------------------------------------------------------------------------------------------------------------------------------

public class Stats
{

    public int LEBEN;

}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...