From 56ec19c0b5f6c9dc31f40d7cd6da398603b5b4d0 Mon Sep 17 00:00:00 2001 From: Borworntat Dendumrongkul <64594596+MasterIceZ@users.noreply.github.com> Date: Tue, 19 Jan 2021 13:41:56 +0700 Subject: [PATCH] Update key.cs --- key.cs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/key.cs b/key.cs index a2459e9..381c14a 100644 --- a/key.cs +++ b/key.cs @@ -1,18 +1,30 @@ + /* - * ใส่ใน OBJ ที่ใช้เป็นกุญแจ + * ใส่ใน Player */ using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; -public class key : MonoBehaviour +public class player_health : MonoBehaviour { - public GameObject keyhole; - void OnCollisionEnter(Collision other) { - if(other.gameObject == keyhole){ - Destroy(gameObject); + public int damage; //ดาเมจของกระสุน + public int MaxHealth; + public int x,y,z; //จุดเริ่มต้นของ Player + private int health; + void Start(){ + SetHealth(MaxHealth); + } + void OnCollisionEnter(Collision other){ + if(other.gameObject.tag == "Bullet"){ Destroy(other.gameObject); + health -= damage; } } + + void SetHealth(int MaxHealth){ + health = MaxHealth; + gameObject.transform.position = new Vector3(x,y,z); + } }