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

Assets\RayCastShoot.cs(43,14): error CS1513: } expected

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

  1. limeeyes

    limeeyes

    Joined:
    Oct 15, 2020
    Posts:
    8
    i have this problem and im still learning C# im stuck on this error can u help me
     
  2. Terraya

    Terraya

    Joined:
    Mar 8, 2018
    Posts:
    646
    yes, we would need to see your code so we can find the missing "}" you forget to place at line 43 :)
     
  3. limeeyes

    limeeyes

    Joined:
    Oct 15, 2020
    Posts:
    8
    here is my code

    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;
    }
    }
     
  4. BABIA_GameStudio

    BABIA_GameStudio

    Joined:
    Mar 31, 2020
    Posts:
    488
    Code (csharp):
    1. if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out hit, weaponRange));
    You have a semi-colon at the end of this line which should not be there. Get rid of the ;
     
    Terraya likes this.
  5. limeeyes

    limeeyes

    Joined:
    Oct 15, 2020
    Posts:
    8
    hello um i get a error if i get rid of it
    Assets\RayCastShoot.cs(38,45): error CS1061: 'Transform' does not contain a definition for 'Position' and no accessible extension method 'Position' accepting a first argument of type 'Transform' could be found (are you missing a using directive or an assembly reference?)
     
  6. limeeyes

    limeeyes

    Joined:
    Oct 15, 2020
    Posts:
    8
    and also it is also not finished with script
     
  7. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,723
    Because you have
    gunEnd.Position
    where you should have
    gunEnd.position
    . Capitalization matters.
     
    Joe-Censored and matkoniecz like this.