Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

using System.Collections; using UnityEngine; public class RayCastShoot : MonoBehaviour { public

Discussion in 'Scripting' started by limeeyes, Nov 10, 2020.

  1. limeeyes

    limeeyes

    Joined:
    Oct 15, 2020
    Posts:
    8
    using System.Collections;
    using UnityEngine;

    public class RayCastShoot : MonoBehaviour
    {
    public int gunDamage = 1;
    public float fireRate = .25f;
    public float weaponRange = 50f;
    public float hitForce = 100f;
    public Transform gunEnd;


    private Camera fpsCam;
    private WaitForSeconds shotDuration = new WaitForSeconds(.07f);
    private AudioSource gunAudio;
    private LineRenderer laserLine;
    private float nextFire;

    void Start()
    {
    laserLine = GetComponent<LineRenderer>();
    gunAudio = GetComponent<AudioSource>();
    fpsCam = GetComponentInParent<Camera>();
    }


    void Update()
    {
    if (Input.GetButtonDown("Fire1") && Time.time > nextFire)
    {
    nextFire = Time.time + fireRate;

    StartCoroutine(ShotEffect());

    Vector3 rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0));
    RaycastHit hit;

    laserLine.SetPosition(0, gunEnd.Position);

    if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out hit, weaponRange));
    {
    laserLine.SetPosition(1, hit.point);
    }
    else
    {
    laserLine.SetPosition(1, rayOrigin + (fpsCam.transform.forward * weaponRange));
    }
    }
    }

    private IEnumerator ShotEffect()
    {
    gunAudio.Play();
    laserLine.enabled = true;
    yield return shotDuration;
    laserLine.enabled = false;
    }
    }







    where do i put the }
     
  2. limeeyes

    limeeyes

    Joined:
    Oct 15, 2020
    Posts:
    8
    i put title wrong LOO it suppoes to be Assets\RayCastShoot.cs(43,14): error CS1513: } expected
     
  3. limeeyes

    limeeyes

    Joined:
    Oct 15, 2020
    Posts:
    8
    im also not done with script yet jsut need to fix the error then im good
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,580
  5. UnityMaru

    UnityMaru

    Community Engagement Manager Unity Technologies

    Joined:
    Mar 16, 2016
    Posts:
    1,227
    He's right - I'll move the thread but please try to be more clearer in your posting.
     
  6. BABIA_GameStudio

    BABIA_GameStudio

    Joined:
    Mar 31, 2020
    Posts:
    488
    On this line
    if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out hit, weaponRange));
    get rid of the ; at the end of it.