Search Unity

  1. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted beginner problem Help Needed Error CS0103

Discussion in 'Scripting' started by FirstBB8Droid, May 31, 2020.

  1. FirstBB8Droid

    FirstBB8Droid

    Joined:
    May 17, 2020
    Posts:
    39
    I'm making an FPS and I'm working on a grappling hook using a youtube tutorial and I'm getting on my script the error
    Assets\scripts\Grappling hook scripts\GrapplingHook.cs(28,27): error CS0103: The name 'Fire2' does not exist in the current context
    and the warnings
    Identifier uniqueness violation: 'Name:pasted__pCylinder3, Type:Mesh'. Multiple Objects with the same name/type are generated by this Importer. There is no guarantee that subsequent imports of this asset will properly re-link to these targets.
    UnityEngine.GUIUtility:processEvent (int,intptr,bool&)
    and
    Unable to open Assets/grapplinghook.fbx: Check external application preference
    here's the code for the grappling hook
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class GrapplingHook : MonoBehaviour
    6. {
    7.  
    8.     public GameObject hook;
    9.     public GameObject hookHolder;
    10.  
    11.     public float HookTravelSpeed;
    12.     public float PlayerTravelSpeed;
    13.  
    14.     public static bool fired;
    15.     public static bool hooked;
    16.  
    17.     public float maxDistance;
    18.     private float currentDistance;
    19.     // Start is called before the first frame update
    20.     void Start()
    21.     {
    22.        
    23.     }
    24.  
    25.     // Update is called once per frame
    26.     void Update()
    27.     {
    28.         if (Input.GetAxis(Fire2) && fired == false)
    29.             fired = true;
    30.         if (fired == true)
    31.         {
    32.             hook.transform.Translate(Vector3.forward * Time.deltaTime * HookTravelSpeed);
    33.             currentDistance = Vector3.Distance(transform.position, hook.transform.position);
    34.  
    35.             if (currentDistance >= maxDistance)
    36.                 ReturnHook();
    37.  
    38.         }
    39.        
    40.     }
    41.     void ReturnHook()
    42.     {
    43.         hook.transform.position = hookHolder.transform.position;
    44.         fired = false;
    45.         hooked = false;
    46.     }
    47. }
    48.  
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    1,704
    If "Fire2" is an axis from the InputManager, you're probably missing some quotes:
    Code (CSharp):
    1. Input.GetAxis("Fire2")
     
  3. FirstBB8Droid

    FirstBB8Droid

    Joined:
    May 17, 2020
    Posts:
    39
    I did that and that fixed one problem but now it's showing me another it now says
    Assets\scripts\Grappling hook scripts\GrapplingHook.cs(28,13): error CS0019: Operator '&&' cannot be applied to operands of type 'float' and 'bool'
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    1,704
    Try this:
    Code (CSharp):
    1. if (Input.GetAxis("Fire2") != 0 && fired == false)
     
    FirstBB8Droid likes this.
  5. FirstBB8Droid

    FirstBB8Droid

    Joined:
    May 17, 2020
    Posts:
    39
    thanks man that fixed my issue,
     
unityunity