Question by
arasioicin · Aug 17, 2020 at 09:08 AM ·
scripting problemshootingshoottop down shooter
My bullet does not go to where i want.When i click down it goes up.Here is my script. TopDownShooter2D
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Weapon : MonoBehaviour {
public GameObject projectile;
public Transform shotPoint;
private float timeBtwShots;
public float startTimeBtwShots;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
private void Update()
{
if (timeBtwShots <= 0)
{
if (Input.GetMouseButtonDown(0))
{
Instantiate(projectile, shotPoint.position, transform.rotation);
timeBtwShots = startTimeBtwShots;
}
}
else
{
timeBtwShots -= Time.deltaTime;
}
}
}
BULLETSCRİPT
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Bullet : MonoBehaviour {
public float speed;
public float lifeTime;
public GameObject destroyEffect;
private void start()
{
Invoke("DestroyProjectile", lifeTime);
}
private void Update()
{
transform.Translate(transform.up * speed * Time.deltaTime);
}
void DestroyProjectile()
{
Instantiate(destroyEffect, transform.position, Quaternion.identity);
Destroy(gameObject);
}
}
Comment
Your answer
Follow this Question
Related Questions
NEED HELP PLEASE! Unexpected symbol. 0 Answers
Shoot until i release the button, but with a fire ratio 2 Answers
The bullet hole colliding with player and "Triggers" 0 Answers
Shots don´t go forward 0 Answers
Problem with a shooting script. 0 Answers