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 bullet hit player now?

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.        
    17.         transform.position = Vector2.MoveTowards(transform.position, hedef.position, 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 you again ...you need to do it better explain a bit more of what happening..and what do you want
     
    Kurt-Dekker likes this.
  3. Yanne065

    Yanne065

    Joined:
    Feb 24, 2018
    Posts:
    175
    didn't you use vector3 lerp on the previous version of this scripts
     
  4. huseyinbaba58

    huseyinbaba58

    Joined:
    Feb 12, 2020
    Posts:
    146
    This is a bullet script.
    The bullet can't hit player now.
    I want to the bullet can hit player.
     
  5. huseyinbaba58

    huseyinbaba58

    Joined:
    Feb 12, 2020
    Posts:
    146
    No. That is a different script.
    Just, variables were similar
     
  6. Yanne065

    Yanne065

    Joined:
    Feb 24, 2018
    Posts:
    175
    Since you looking at target on update you could just use Translate with forward directions
     
  7. huseyinbaba58

    huseyinbaba58

    Joined:
    Feb 12, 2020
    Posts:
    146
    I understood.I hope script will run.