I wanna combine 2 scripts from different objects. My first script like this;
//ScriptA
...
public void CastRay()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, Mathf.Infinity);
if (hit.transform.gameObject.tag == "BadGuy") //this line give me "NullReferenceException: Object reference not set to an instance of an object" but it works. I can't get it.
{
gameController.AddScore(scoreValue);
Destroy(hit.transform.gameObject);
}
else
{
gameController.LessScore(scoreValue);
Destroy(hit.transform.gameObject);
}
}
And my other script;
//ScriptB
...
public void ShowOnScreen(GameObject[] thisList)
{
for (int i = 0; i < thisList.Length; i++)
{
Instantiate(thisList[i], Vector3.Lerp(startPoint, endPoint, (float)i / (thisList.Length - 1)), Quaternion.identity);
}
if (thisList == enemylist1)
{
Debug.Log("Enemy");
}
else
{
Debug.Log("No Enemy");
}
}
Both of them works fine but I wanna use “if statements” like this;
...
if (thisList == enemylist1 && hit.transform.gameObject.tag == "BadGuy")
{
gameController.AddScore(scoreValue);
Destroy(hit.transform.gameObject);
}
else
{
gameController.LessScore(scoreValue);
Destroy(hit.transform.gameObject);
}
}
I have list of prefab more than one and they showing on screen randomly. I wanna customize every list. Thanks for helping. Yes I am newbie for C# and Unity ^^ By the way,sorry for my bad English ![]()