- Home /
Question by
jondalarw · Apr 30, 2020 at 05:19 PM ·
errorerror message
unity object reference not set to an instance of an object
I am attempting to execute a method from another script and can not seem to do it. I get this error "unity object reference not set to an instance of an object".`using System; using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Battle : MonoBehaviour { public Transform objToTele, tpLoc, enemyToTele, enemyTeleLoc;
private void OnTriggerStay(Collider other)
{
}
public void makeBattle(bool inBattle)
{
objToTele.transform.position = tpLoc.transform.position;
enemyToTele.transform.position = enemyTeleLoc.transform.position;
inBattle = true;
}
}`
public class PlayerController : MonoBehaviour
{
public float speed;
Rigidbody myRigidBody;
public bool inBattle;
void Start()
{
myRigidBody = GetComponent<Rigidbody>();
inBattle = false;
}
void Update()
{
//PlayerMovement();
}
private void FixedUpdate()
{
if(inBattle == false)
{
PlayerMovement();
}
else
{
print("in battle, can not move");
}
}
void PlayerMovement()
{
float hor = Input.GetAxis("Horizontal");
float ver = Input.GetAxis("Vertical");
Vector3 playerMovement = new Vector3(0f, 0f, ver) * speed * Time.deltaTime;
transform.eulerAngles += new Vector3(0f, hor, 0f);
transform.Translate(playerMovement, Space.Self);
}
void OnTriggerEnter(Collider triggerCollider)
{
if(triggerCollider.gameObject.tag == "Enemy")
{
Battle battle = gameObject.GetComponent<Battle>();
battle.makeBattle(inBattle);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
All scripts in unity have stopped working 1 Answer
Sprite Atlas (Sprite Atlas UI) Error 0 Answers