Question by
Big-Jonny · Jul 08, 2018 at 08:04 PM ·
damagegun scriptgunfire
How do i get my bullets to do damage?,i have a player than can shoot bullets but i don't know how to make the bullets do damage and go after. Can anyone help?
here is the C# script I have right now using System.Collections; using System.Collections.Generic; using UnityEngine;
public class projectile_shooter : MonoBehaviour{ GameObject prefab; void Start () { prefab = Resources.Load("projectile") as GameObject; }
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0))
{
GameObject projectile = Instantiate(prefab) as GameObject;
projectile.transform.position=transform.position+Camera.main.transform.forward * 2;
Rigidbody rb = projectile.GetComponent<Rigidbody>();
rb.velocity = Camera.main.transform.forward * 1000;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Gunshot not working? 0 Answers
How to deal damage to only enemy hit? 2 Answers
Basic damage script is not working 0 Answers
How do i make my gun do damage? 1 Answer
How to make gun shoot in the crosshair & automatic fire (Javascript) 1 Answer