Hi, I’m a newbie in Unity and I am having a problem that I don’t know what to do. I am customizing my Survival Shooter and I want to put “foods” on the way, so my player can pick it and up its health. I am using the same concept of Roll a Ball. See my code:
using UnityEngine;
public class PlayerMovement : MonoBehaviour{
public float speed = 6f;
Vector3 movement;
Animator anim;
Rigidbody playerRigidbody;
int floorMask;
float camRayLength = 100f;
void Awake(){
floorMask = LayerMask.GetMask ("Floor");
anim = GetComponent<Animator> ();
playerRigidbody = GetComponent<Rigidbody> ();
}
//Other codes here
void OnTriggerEnter(Collider other){
if (other.gameObject.CompareTag ("PickFood")) {
other.gameObject.SetActive (false);
}
}
}
I set my Prefabs and cubes with the tag PickFood and put t “on trigger” in Box Collider… But when I press play, the cubes just disappear. And if I set "other.gameObject.SetActive’ to ‘true’, my player just run through my GameObject. Can somebody help me, please!?
(Sorry about my English. Thanks!!!)