so I'm a bit new to C# with random math and I learned how to make a rifle, pistol, etc. But I want to learn how to make a shotgun with raycast, not with projectile. With raycast's I tired to do more then 1 raycast but didn't know how to make them random so now I'm just stuck with 1 raycast. I want to make a random spread when I shoot. Here is the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShotGun : MonoBehaviour {
private int pellets = 9;
private float spreadAngle = 10f;
private float damage = 10f;
private float range = 1000f;
private Camera fpsCam;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (Input.GetButtonDown("Fire1"))
{
ShotgunRay();
}
}
private void ShotgunRay()
{
RaycastHit hit;
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
{
Health_Armor target = hit.transform.GetComponent<Health_Armor>();
if (target != null)
{
target.TakeDamage(damage);
}
}
}
}
Mathf.Random
method. UseRandom.Range(-1f, 1f)
instead. – Manyplies