You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class CharacterController : MonoBehaviour
|
|
|
|
{
|
|
|
|
public Rigidbody characterRigidbody;
|
|
|
|
public float swingForce = 10f;
|
|
|
|
public float Health;
|
|
|
|
public HingeJoint SpineHingeJoint;
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
// Control the character with horizontal input
|
|
|
|
float input = Input.GetAxis("Horizontal");
|
|
|
|
characterRigidbody.AddForce(Vector2.right * input * swingForce);
|
|
|
|
}
|
|
|
|
private void OnCollisionEnter(Collision collision)
|
|
|
|
{
|
|
|
|
Debug.Log("Collided with: "+collision.gameObject.name);
|
|
|
|
if(collision.gameObject.layer==LayerMask.NameToLayer("Obstacle"))
|
|
|
|
{
|
|
|
|
Health -= 0.5f;
|
|
|
|
UIManager.instance.UpdateHealth();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|