mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-09-14 21:35:17 -05:00
-created a script for breakable objects
-updated block prefabs (updated size/added breakable script) -added demo scene for blocks/breakable script
This commit is contained in:
37
Assets/Scripts/Environment/BreakableBlock.cs
Normal file
37
Assets/Scripts/Environment/BreakableBlock.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BreakableBlock : MonoBehaviour
|
||||
{
|
||||
//kicking power 150 (250 for stornger kick)
|
||||
public float health;
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
//if health is not set, default it to 1
|
||||
if(health == 0){
|
||||
|
||||
health = 3;
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void damage(float kickPower){
|
||||
int totalDamage = (int)(kickPower / 50.0);
|
||||
health -= totalDamage;
|
||||
Debug.Log(health);
|
||||
//if item is at 0 health
|
||||
if(health <= 0){
|
||||
destroy();
|
||||
}
|
||||
}
|
||||
//called once health here is zero
|
||||
public void destroy(){
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Environment/BreakableBlock.cs.meta
Normal file
11
Assets/Scripts/Environment/BreakableBlock.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5fa71751031fd4542bb5ef0d2c9672cf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user