Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Why can not this game object take damage player?

Discussion in 'Scripting' started by huseyinbaba58, Aug 15, 2020.

  1. huseyinbaba58

    huseyinbaba58

    Joined:
    Feb 12, 2020
    Posts:
    146
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class vurucu : MonoBehaviour
    6. {
    7.     public Transform hedef;
    8.     void Awake()
    9.     {
    10.         hedef = GameObject.FindGameObjectWithTag("Player").transform;
    11.     }
    12.  
    13.     void Update()
    14.     {
    15.         transform.LookAt(hedef);
    16.         Vector3 yonelim = hedef.position - transform.position;
    17.         transform.position = Vector3.Lerp(transform.position, yonelim, 10f * Time.deltaTime); //Buraya doğru gidecek.
    18.     }
    19.     void OnTriggerEnter2D(Collider2D carpismis)
    20.     {
    21.         if(carpismis.gameObject.tag=="Player")
    22.         {
    23.             Debug.Log("Vurdum onu");
    24.  
    25.             carpismis.gameObject.GetComponent<Yara>().canHasari(10f); //10f can hasarı olacak.
    26.         }
    27.     }
    28. }
     
  2. Yanne065

    Yanne065

    Joined:
    Feb 24, 2018
    Posts:
    175
    Man how do you want people to answer it ..did the debug log pop out when trigger?
     
  3. huseyinbaba58

    huseyinbaba58

    Joined:
    Feb 12, 2020
    Posts:
    146
    Debug.log can't create output now.
     
  4. Yanne065

    Yanne065

    Joined:
    Feb 24, 2018
    Posts:
    175
    Then check if the tag correctly and set up the triggers properly etc..
     
    huseyinbaba58 likes this.
  5. huseyinbaba58

    huseyinbaba58

    Joined:
    Feb 12, 2020
    Posts:
    146
    The tag is true but collider is disabled I think