Basic game completed
This commit is contained in:
45
3D FPS/Assets/Scripts/Entities/Entity.cs
Normal file
45
3D FPS/Assets/Scripts/Entities/Entity.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class Entity : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float startingHealth;
|
||||
[SerializeField] private int scoreValue;
|
||||
private float health;
|
||||
private Transform player;
|
||||
|
||||
public float Health
|
||||
{
|
||||
get
|
||||
{
|
||||
return health;
|
||||
}
|
||||
set
|
||||
{
|
||||
if(value <= 0f)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
PlayerHealth playerHealth = player.GetComponent<PlayerHealth>();
|
||||
playerHealth.AddScore(scoreValue);
|
||||
}
|
||||
else health = value;
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
Health = startingHealth;
|
||||
|
||||
GameObject playerObject = GameObject.FindWithTag("Player");
|
||||
if (playerObject != null)
|
||||
{
|
||||
player = playerObject.transform;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Player not found! Ensure the player has the tag 'Player'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
11
3D FPS/Assets/Scripts/Entities/Entity.cs.meta
Normal file
11
3D FPS/Assets/Scripts/Entities/Entity.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b4d54af625597c4786158cd650f5d17
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user