I want my camera shake when isDamaging = true at EnemyDamage script but It wont happent
I dont even get why theres a problem with that stuff it doesnt make sense its looking like %100 true
when I printed the isDamaing its also says it =true but dont work
shake script:
using System.Collections;
using UnityEngine;
public class gotHit : MonoBehaviour
{
public bool start = false;
public AnimationCurve curve;
public float duration = 1f;
private EnemyDamage enemyDamage;
public Transform camera;
private Coroutine shakeCoroutine;
private void Awake()
{
enemyDamage = GameObject.FindWithTag("ucgen").GetComponent<EnemyDamage>();
}
void Update()
{
if (start)
{
start = false;
Debug.Log("start ile sarsılma başlatılıyor.");
StartShaking();
}
if (enemyDamage.isDamaging)
{
Debug.Log("enemyDamage.isDamaging ile sarsılma başlatılıyor.");
StartShaking();
enemyDamage.isDamaging = false;
}
}
void StartShaking()
{
if (shakeCoroutine != null)
{
StopCoroutine(shakeCoroutine);
}
shakeCoroutine = StartCoroutine(Shaking());
}
IEnumerator Shaking()
{
Vector3 startPosition = camera.position;
float elapsedTime = 0f;
while (elapsedTime < duration)
{
elapsedTime += Time.deltaTime;
float strength = curve.Evaluate(elapsedTime / duration);
camera.position = startPosition + Random.insideUnitSphere * strength;
yield return null;
}
camera.position = startPosition;
}
}
enemy damage script:
using System.Collections;
using UnityEngine;
public class EnemyDamage : MonoBehaviour
{
public int enemyTriangleDamage = 2;
private PlayerHealth playerHealth;
public bool isDamaging = false; // Coroutine'in tekrar başlamasını engellemek için bayrak
private void Awake()
{
// Oyuncu sağlığı bileşenini bulun
GameObject player = GameObject.FindWithTag("Player");
if (player != null)
{
playerHealth = player.GetComponent<PlayerHealth>();
}
}
private void Update()
{
Debug.Log("isDamaging durumu: " + isDamaging);
}
private void OnCollisionStay2D(Collision2D collision2D)
{
if (!isDamaging && collision2D.gameObject.CompareTag("Player"))
{
StartCoroutine(Diee());
}
}
IEnumerator Diee()
{
isDamaging = true;
yield return new WaitForSeconds(0.5f);
if (playerHealth != null)
{
playerHealth.TakeDamage(enemyTriangleDamage);
}
isDamaging = false;
}
}
I tried chatgpt too but it can t help me too
New contributor
ybay is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.