- Home /
The question is answered, right answer was accepted
Why wont my attack script get the data from my movement script (error)?
So yeah, when I play test it, I get error in the line of the mouse0 input. Any idea?
Attack Script:
public float attackRate = 2f;
float nextattackTime = 0f;
public PlayerController PlayerController;
void Update()
{
if (Time.time >= nextattackTime)
{
if (Input.GetKeyDown(KeyCode.Mouse0) && (PlayerController.isJumping == true))
{
CritAttack();
nextattackTime = Time.time + 1f / attackRate;
}
}
}
Movement script:
void OnTriggerEnter2D(Collider2D collision)
{
if(collision.gameObject.tag == "Platform")
{
isJumping = false;
}
}
void OnTriggerExit2D(Collider2D collision)
{
if (collision.gameObject.tag == "Platform")
{
isJumping = true;
}
}
If you get an error then post the error. The error is the one that tells you what's wrong. I guess you have either something like ReferenceNotAssignedException
or NullReferenceException
. This will with a probability of 99.9% be because you did not assign a value to PlayerController
.
As i read that please note: NEVER assign the name of a variable to be the same as the type it is. so PlayerController PlayerController
is a NO NO. If you want to keep it close make it PlayerController playerController
.
Answer by privatecontractor · Jan 21 at 09:08 PM
Hi, @duducarry ,
At top you have:
public PlayerController PlayerController;
change for:
public PlayerController m_PlayerController;
then :
if (Input.GetKeyDown(KeyCode.Mouse0) && (PlayerController.isJumping == true))
Change for:
if (Input.GetKeyDown(KeyCode.Mouse0) && (m_PlayerControler.isJumping == true))
Also remeber about ataching component in inspector for it.
Hope will do.