Hey @dragonking300,
If I understood correctly, you want to check multiple tags at once!
Try adding a list with tags, and a method that checks if a certain string (tag) is in that list.
Which would look something like this:
using UnityEngine;
using System.Collections;
using System.Collections.Generic; // NEW
public class Jump : MonoBehaviour
{
public bool OnGround;
private Rigidbody rb;
// NEW
private List tagsToCompare = new List()
{
"Ground",
"tag2",
"tag3" // Note how the last one doesn't need a comma.
};
void Start()
{
OnGround = true;
Debug.Log( "OnGround set to true in Start" );
rb = GetComponent();
}
void Update()
{
if( OnGround )
{
if( Input.GetButton( "Jump" ) )
{
rb.velocity = new Vector3( 0.0f, 10f, 0.0f );
OnGround = false;
Debug.Log( "OnGround set to false in Update" );
}
else
{
}
}
}
void OnCollisionEnter( Collision other )
{
Debug.Log( "Collision entered with tag named: " + other.gameObject.tag );
if( isTargetTag( other.gameObject.tag ) ) // NEW
{
OnGround = true;
Debug.Log( "OnGround Set To true in OnCollisionEnter, collided with tag: " + other.gameObject.tag );
}
else
{
OnGround = false;
Debug.Log( "OnGround Set To false in OnCollisionEnter, collided with tag: " + other.gameObject.tag );
}
}
// NEW
private bool isTargetTag( string tagToCheck )
{
return tagsToCompare.Contains( tagToCheck );
}
}
I added // NEW comments in places where I changed your code.
I hope that helps, if it did, please accept this answer, it'd be much appreciated!
If you need any more details, let me know! :)
Cheers,
ThePersister
↧