using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class vurucu : MonoBehaviour
{
public Transform hedef;
void Awake()
{
hedef = GameObject.FindGameObjectWithTag("Player").transform;
}
void Update()
{
transform.LookAt(hedef);
transform.position = Vector2.MoveTowards(transform.position, hedef.position, 10f * Time.deltaTime); //Buraya doğru gidecek.
}
void OnTriggerEnter2D(Collider2D carpismis)
{
if(carpismis.gameObject.tag=="Player")
{
Debug.Log("Vurdum onu");
carpismis.gameObject.GetComponent<Yara>().canHasari(10f); //10f can hasarı olacak.
}
}
}
Putting a question in a title that makes little sense on it’s own isn’t enough to get help. We need more context and honestly I have no clue what you are asking. I’m not seeing any obvious issues about code that shouldn’t execute.
I am developing 2D hyper casual game.But OnCollisionEnter2D can not work now.
Unfortunately, that isn’t enough info… Does Update run? Did you add a debug outside your if statement in OnTriggerEnter2D and see if that runs? Do you have the proper colliders setup and one is a trigger? Is your player tagged correctly? (Player and not player for example as caps matter).
Are the scripts even on the proper objects?
I was careful that what you were saying.
But onCollisionEnter2D can’t still run.
I can’t really help you because you’re not providing a lot of information. So it’s impossible for me to tell you what is going wrong. Code wise, it appears to be correct.
The only other thing to check is you have a Rigidbody2D attached to one of the two objects as they mention in their docs.
Both of objects are contains Rigidbody2D.Despite of this situations. OnCollisionEnter2D can’t run.
I don’t have any lexical error.But I couldn’t clutch truly.
Sorry, at this point I have no way of helping you. You just need to add some more debug messages and check to make sure things are colliding and setup correctly.
Debug.Log can’t generate output.
Error message can’t be illustrated at the moment.
Tag is true.
I checked name of tag.
Also,I checked collider components.
If Debug.Log isn’t printing anything out, then your code is not running.
-
Check that your scripts are properly attached to GameObjects in the scene;
-
Check that their names match the script name;
-
Check that your Unity callback methods (Update, OnTriggerEnter2D) are spelled and capitalized properly.
-
Check that you have the right kind of collider attached (2D collider for 2D functions, normal collider for 3D functions)
Thanks PrateorBlue