I have a powerup script and wanted to apply a jump boost when the player hits a particular powerup.
I have tried the following…
void OnTriggerEnter2D (Collider2D other)
{
if (other.tag == "Player") {
switch (PointType.ToString ()) {
//Removed unneeded cases for the forum post
case "ReverseGravity":
print ("flip it");
other.transform.Rotate(new Vector3 (0, 0, 180f)); //works
other.GetComponent<SpriteRenderer>().flipX = true; //works
other.GetComponent<Rigidbody2D>().gravityScale = -10f; //works
other.GetComponent<PlatformerCharacter2D>().m_JumpForce = 800f; //fails to build without errors - It says the component is out of context
break;
}
}
Im not super versed in c#. The above “JumpForce” is part of the standard assets package.
The script that controls JumpForce is PlatformerCharacter2D. I am able to set the value in the gui of the unity editor but not in the scripts.