- Home /
Question by
zak666 · Jun 27, 2017 at 10:54 PM ·
raycastgunlinerenderer
RayCast Line Not Rotating with Gun?
Hey gang Have my Recast machine gun looking beautiful here only problem is "Forward " Dose not rotate when I rotate my Gun and keeps facing the One-direction...
public float FireRate = 0.1f;
private float NextFire;
public float ShootRange = 60;
public float Damage = 1.0f;
public float Shotduration = 0.2f;
private LineRenderer BulletTracer;
private bool ReadytoFire;
void Start(){
BulletTracer = GetComponent<LineRenderer> ();
}
void Update(){
if (Input.GetButton ("Fire1") && Time.time > NextFire) {
NextFire = Time.time + FireRate;
StartCoroutine(ShotEffect());
RaycastHit hit;
BulletTracer.SetPosition (0, transform.position);
if (Physics.Raycast (transform.position, transform.forward, out hit, ShootRange)) {
BulletTracer.SetPosition (1, hit.point);
} else{
BulletTracer.SetPosition(1, new Vector3(0, 0, ShootRange));
}
if(hit.collider.gameObject.tag == "Enemyy"){
hit.collider.SendMessage("GunHit", Damage, SendMessageOptions.DontRequireReceiver );
}
}
}
private IEnumerator ShotEffect(){
BulletTracer.enabled = true;
yield return Shotduration;
BulletTracer.enabled = false;
}
}
Comment
Your answer
Follow this Question
Related Questions
Creating a Ray Gun 1 Answer
Simple wire/cable 1 Answer
How do I create bullet hole for my gun? 0 Answers
Error with gun aim to the mouse 1 Answer
line renderer in raycast with one starting point (mouse input) and multiple end point 2 Answers