heres my code im really confused
i dont know what to do and
i also have the same problem but for start
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyBullets : MonoBehaviour
{
private GameObject player;
private Rigidbody2D rb;
public float force;
void Start()
{
player = GameObject.FindGameObjectWithTag("Player");
Vector3 direction = player.transform.position - transform.position;
rb.velocity = new Vector2(direction.x, direction.y).normalized * force;
}
void Update ()
{
timer += Time.deltaTime;
if(timer > 10)
{
die();
}
}
void OnTriggerEnter2D (Collider2D hitInfo)
{
if(other.gameObject.CompareTag("Player"))
{
die();
}
}
private void die()
{
Destroy(gameObject);
}
}
↧