Skip to main content
Sign in
Snippets Groups Projects
Commit c2de8b4c authored by Salomo309's avatar Salomo309
Browse files

feat: pet

parent 6f84849e
Branches
Tags
No related merge requests found
fileFormatVersion: 2
guid: 44c5a4345914ba142a9042e0a9f612d3
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
public class PetAttacker : MonoBehaviour
{
public int damageAmount = 20;
public string targetTag = "Enemy";
public ParticleSystem hitParticles;
private void Update()
{
FindNearestEnemy();
}
private void FindNearestEnemy()
{
GameObject[] enemies = GameObject.FindGameObjectsWithTag(targetTag);
float closestDistanceSqr = Mathf.Infinity;
GameObject nearestEnemy = null;
foreach (GameObject enemy in enemies)
{
float distanceToEnemy = (enemy.transform.position - transform.position).sqrMagnitude;
if (distanceToEnemy < closestDistanceSqr)
{
closestDistanceSqr = distanceToEnemy;
nearestEnemy = enemy;
}
}
if (nearestEnemy != null)
{
AttackEnemy(nearestEnemy);
}
}
private void AttackEnemy(GameObject enemy)
{
if (enemy.CompareTag("Raja"))
{
RajaHealth rajaHealth = enemy.GetComponent<RajaHealth>();
if (rajaHealth != null)
{
rajaHealth.TakeDamage(damageAmount, hitParticles.transform.position);
}
}
else if (enemy.CompareTag("Jenderal"))
{
JenderalHealth jenderalHealth = enemy.GetComponent<JenderalHealth>();
if (jenderalHealth != null)
{
jenderalHealth.TakeDamage(damageAmount, hitParticles.transform.position);
}
}
else if (enemy.CompareTag("KepalaKeroco"))
{
KepalaKerocoHealth kepalaKerocoHealth = enemy.GetComponent<KepalaKerocoHealth>();
if (kepalaKerocoHealth != null)
{
kepalaKerocoHealth.TakeDamage(damageAmount, hitParticles.transform.position);
}
}
else if (enemy.CompareTag("Keroco"))
{
KerocoHealth kerocoHealth = enemy.GetComponent<KerocoHealth>();
if (kerocoHealth != null)
{
kerocoHealth.TakeDamage(damageAmount, hitParticles.transform.position);
}
}
}
}
fileFormatVersion: 2
guid: 76ae8ec4b344d5d4c81eb81460792e9e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using Nightmare;
using UnityEngine;
public class PetHealer : MonoBehaviour
{
public int healAmount = 10;
public float healInterval = 2f;
private PlayerHealth playerHealth;
private void Awake()
{
playerHealth = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerHealth>();
InvokeRepeating(nameof(HealPlayer), healInterval, healInterval);
}
private void HealPlayer()
{
if (playerHealth != null)
{
playerHealth.currentHealth += healAmount;
}
}
}
fileFormatVersion: 2
guid: 335afb094ee9bb943978eb1f537bf903
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PetHeatlh : MonoBehaviour
{
public int startingHealth = 100;
public int currentHealth;
public bool isDead;
public bool damaged;
void Awake()
{
currentHealth = startingHealth;
}
void Update()
{
}
public void TakeDamage(int amount)
{
currentHealth -= amount;
if (currentHealth <= 0)
{
currentHealth = 0;
isDead = true;
Destroy(gameObject);
}
else
{
damaged = true;
}
}
public void CheatPetFullHP()
public void CheatPetFullHP()
{
currentHealth = 100;
}
}
fileFormatVersion: 2
guid: e13c7ffbce9ab78478de6505a5d1927d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
public class PetIncreaser : MonoBehaviour
{
public float attackIncreasePercentage = 20f;
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Jenderal"))
{
JenderalAttack jenderalShooting = other.GetComponent<JenderalAttack>();
if (jenderalShooting != null)
{
jenderalShooting.IncreaseAttack(attackIncreasePercentage);
}
}
else if (other.CompareTag("Raja"))
{
RajaAttack rajaShooting = other.GetComponent<RajaAttack>();
if (rajaShooting != null)
{
rajaShooting.IncreaseAttack(attackIncreasePercentage);
}
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 2a6ad8056f417284fbfc3a518b889690
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
public class PetMovement : MonoBehaviour
{
public float followDistance = 4f;
public string playerTag = "Player";
private Transform player;
void Awake()
{
player = GameObject.FindGameObjectWithTag(playerTag).transform;
if (player == null)
{
Debug.LogError("Player not found! Make sure the player is tagged correctly.");
}
}
void Update()
{
if (player != null)
{
Vector3 directionToPlayer = player.position - transform.position;
//float distanceToPlayer = directionToPlayer.magnitude;
Vector3 targetPosition = player.position - directionToPlayer.normalized * followDistance;
transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime);
}
}
}
fileFormatVersion: 2
guid: e8e40418ab897f743a587a87b683168d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment