Jump to content

pomoc Java Help


LemoNSK

Recommended Posts

Prosím Vás jestli nekdo umí v Jave teda v Unity Enginu muže mi prosím někdo opravit tenhle error a říct kde je chyba? Už to delam nekolik hodin a stale nic.. Všechno co jsem za tu hodinu udelal bylo špatně.

 

Error: NullReferenceException: Object reference not set to an instance of an object

BushTake.OnTriggerEnter (UnityEngine.Collider Col) (at Assets/Inventory/BushTake.js:62)
 
 
Script:                         --- Tam kde je v tom scriptu hrubé písmo to je ten error..
#pragma strict


var respawnBarries : float = 100.0;
var EmptyBarries : boolean = false;
var Barries : GameObject;
var timerisactive : boolean = false;
var guiShow : boolean = false;
var timergui : float = 4.0;
var givebarries : boolean = false;
private var player : GameObject;


public var inventory : Inventory;

function Start () {

}

function Update () {
	
	if(givebarries == true)
	{
		givebarries = false;
	}
	
	if(timerisactive == true)
	{
		respawnBarries -= Time.deltaTime;
		EmptyBarries = false;
	}

	if(respawnBarries < 0)
	{
		Barries.SetActive (true);
		respawnBarries = 100.0;
	}
	
	if(timergui < 0)
	{
		guiShow = false;
	}

}

function OnTriggerEnter (Col : Collider)
{
  if(Col.tag == "BushPickup")
  {
	if(EmptyBarries == true)
	{

	}
	
	if(EmptyBarries == false)
	{
		Barries.SetActive (false);
		EmptyBarries = true;
		timerisactive = true;
		guiShow = true;
		givebarries = true;
		player.GetComponent(Inventory).barries += 1;
	}
   }	
}

function OnTriggerExit(Col: Collider)
{
	if(Col.tag == "BushPickup")
	{
	
	}
}

function OnGUI()
{
	if(guiShow == true)
	{
	GUI.Box(Rect(Screen.width / 5 - 100, Screen.height / 2 - 160, 300, 20), "Barries has been automatically picked up");
	timergui -= Time.deltaTime;
	}
}

 

Link to comment
Share on other sites

Tak:

1) Toto je Javascript (Unityscript) a nie Java.

2) Pristupujes k neexistujucim objektom. Predpokladam, ze Barries a Inventory referenciam pridelujes hodnoty cez inspector, ale taka premenna player na nic neodkazuje. Nevidim, co mas oznacene v kode hrubou, ale chyba je niekde v OnTriggerEnter:

player.GetComponent(Inventory).barries += 1;

toto ti nepojde, lebo premenna player neodkazuje na ziaden objekt. musis objekt priradit, napr. v OnStart(), alebo sprav z nej public a pridel napevno cez Inspector.

Edited by ZaKlaus
Link to comment
Share on other sites

L

 

Tak:

1) Toto je Javascript (Unityscript) a nie Java.

2) Pristupujes k neexistujucim objektom. Predpokladam, ze Barries a Inventory referenciam pridelujes hodnoty cez inspector, ale taka premenna player na nic neodkazuje. Nevidim, co mas oznacene v kode hrubou, ale chyba je niekde v OnTriggerEnter:

player.GetComponent(Inventory).barries += 1;

toto ti nepojde, lebo premenna player neodkazuje na ziaden objekt. musis objekt priradit, napr. v OnStart(), alebo sprav z nej public a pridel napevno cez Inspector.

Ja v tom toho moc neumím nemohl bys mi prosím napsat příklad nějakej? Když taky nevíš tak napíš nevim.. Když mi napíšeš chybu tak zaroven se to naučím i si zapamatuju.. 

Link to comment
Share on other sites

Je sice pekne, ze si sa pustil do Unity, ale priklady ti nepomozu, ak nebudes vediet samotne zaklady :).

Však ok ale pomoc když v tom umíš by se hodila jako že by si mi pomohl opravit error.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...