Cześć.
Robię grę, w której można strzelać. Chcę zrobić system zabijania przeciwnika kilkoma strzałami z pistoletu. Daje mój skrypt. Wydaje się dobry, ale po strzeleniu w wroga, on od razu umiera. Natomiast mi chodzi o to aby umieral dopiero po otrzymaniu 5 strzałów. Będę wdzięczny za pomoc :).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OponentSystem : MonoBehaviour
{
public float oponentWalkSpeed = 30.0f;
public float oponentDistance = 5.0f;
public float oponentLive = 100.0f;
public float glockPower = 20.0f;
void Start()
{
}
void Update()
{
}
void OnTriggerStay(Collider col)
{
if (col.tag.Equals("Player"))
{
Quaternion targetRotation = Quaternion.LookRotation(col.transform.position - transform.position);
float onlyRotationX = transform.rotation.x;
float onlyRotationZ = transform.rotation.z;
Quaternion oponentRotation = Quaternion.Slerp(transform.rotation, targetRotation, 5.0f * Time.deltaTime);
oponentRotation.x = onlyRotationX;
oponentRotation.z = onlyRotationZ;
transform.rotation = oponentRotation;
float distance = Vector3.Distance(transform.position, col.transform.position);
if (distance > oponentDistance)
{
transform.Translate(Vector3.forward * oponentWalkSpeed * Time.deltaTime);
}
if (col.tag("GlockBullet"))
{
oponentLive -= glockPower;
}
if (col.tag.Equals("GlockBullet") && oponentLive == 0)
{
Dead();
}
}
}
void Dead()
{
Destroy(gameObject, 3.0f);
}
}