Ill make this one simple:
-
Player is tagged Player. Its not being destroyed by contact with any form of destroy by contact script such as the one below.
-
Player is using a Character controller instead of a capsule collider which is necessary for the physics effect needed such as step detection.
using UnityEngine; using System.Collections; using UnityEngine.UI; public class DestroyByContact : MonoBehaviour { public GameObject explosion; public GameObject playerExplosion; public int scoreValue; private GameController gameController; void Start() { GameObject gameControllerObject = GameObject.FindWithTag("GameController"); if (gameControllerObject != null) { gameController = gameControllerObject.GetComponent<GameController>(); } if (gameController == null) { Debug.Log("Cannot find 'GameController' script"); } } void OnTriggerEnter(Collider other) { if (other.CompareTag("Barrier") || other.CompareTag("Enemy")) { return; } if (explosion != null) { Instantiate(explosion, transform.position, transform.rotation); } if (other.tag == "Player") { Instantiate(playerExplosion, other.transform.position, other.transform.rotation); } gameController.AddScore(scoreValue); Destroy(other.gameObject); Destroy(gameObject); } }
-
I can shoot enemies, score points, etc and blow them up. They are not destroying player on contact like they are suppose too.
-
Where do i edit this script in unity 5.3 since there is no “trigger” settings in the character controller?
-
The following is the player movement script i’m using because it works properly and does not allow my character to pass through other object colliders.
//Variables
public float speed = 3.0F;
public float rotateSpeed = 3.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;void Update() { CharacterController controller = GetComponent<CharacterController>(); //Feed moveDirection with input. { transform.Rotate(0, Input.GetAxis("Horizontal") * rotateSpeed, 0); Vector3 forward = transform.TransformDirection(Vector3.forward); float curSpeed = speed * Input.GetAxis("Vertical"); controller.SimpleMove(forward * curSpeed); //Jumping if (Input.GetButton("Jump")) moveDirection.y = jumpSpeed; } //Applying gravity to the controller moveDirection.y -= gravity * Time.deltaTime; //Making the character move controller.Move(moveDirection * Time.deltaTime); }
}