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. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Shooting script

Discussion in 'Scripting' started by Neo_maister, May 24, 2015.

  1. Neo_maister

    Neo_maister

    Joined:
    Apr 16, 2015
    Posts:
    14
    i made this shooting script:
    Code (JavaScript):
    1.   var projectile : Rigidbody;
    2.   var speed = 10;
    3.  
    4.   function update () {
    5.   }
    6.   if(Input.GetButtonUp ("Fire1"))
    7.  
    8.   clone = Instantiate(projectile, transform.position, transform.rotation);
    9.   clone.velocity = transform.TransformDirection(Vector3 (0, 0, speed));
    10.  
    11.   Destroy(clone.gameObject, 5);
    12.  
    but there is 1 console error i cant solve which is this:
    -ArgumentException: Input Button Fire 1 is not setup.
    To change the input settings use: Edit -> Project Settings -> Input
    Shoot.Main () (at Assets/Shoot.js:6)

    can you guys help me
     
  2. Wagwan Tezza

    Wagwan Tezza

    Joined:
    Mar 4, 2015
    Posts:
    1
    im not a programmer learning myself but it looks like u need another set of curley brackets (perenthices or how ever its spelt)or move the one from line 5 to line 12 or wait for someone who nos more to help .
     
  3. RiokuTheSlayer

    RiokuTheSlayer

    Joined:
    Aug 22, 2013
    Posts:
    356
    Your if() statement is outside of the actual method Update(). Move it up so it's like this, and add brackets for the if statment.


    Code (CSharp):
    1. function Update(){
    2.     if(Input.GetButtonUp("Fire1")){
    3.         var clone = Instantiate(projectile, transform.position, transform.rotation);
    4.         clone.velocity = transform.TransformDirection(0,0,speed);
    5.      
    6.         Destroy(clone.gameObject, 5);
    7.     }
    8. }

    Also, you'll probably need to use clone.GetComponent<Rigidbody>().velocity instead of clone.velocity. Not sure how much different the javascript version of unity is, though.
     
  4. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,887
    Aside from the Update thing, it tells you exactly what to do in the error message...

    Input Button Fire1 is not setup
    To change the input settings use: Edit -> Project Settings -> Input

    So you have to go to Input and add an Axis called Fire1.
     
  5. Neo_maister

    Neo_maister

    Joined:
    Apr 16, 2015
    Posts:
    14
    but now it says unknown identifier projectile,speed
     
    Last edited: May 25, 2015
  6. RiokuTheSlayer

    RiokuTheSlayer

    Joined:
    Aug 22, 2013
    Posts:
    356
    I just meant replacing the Update() function, not the entire script.
     
  7. Neo_maister

    Neo_maister

    Joined:
    Apr 16, 2015
    Posts:
    14
    Code (JavaScript):
    1. #pragma strict
    2. var projectile : Rigidbody;
    3.   var speed = 10;
    4.   function update () {
    5.  
    6.   if(Input.GetButtonUp ("Fire1"))
    7.   clone = Instantiate(projectile, transform.position, transform.rotation);
    8.   clone.GetComponent<Rigidbody> = ;transform.TransformDirection(Vector3 (0, 0, speed)).velocity;
    9.   Destroy(clone.gameObject, 5);
    10.   }
    i follow some of your instruction but still get some errors like this
    -BCE0043: Unexpected token: >.
     
  8. RiokuTheSlayer

    RiokuTheSlayer

    Joined:
    Aug 22, 2013
    Posts:
    356