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

GetButtonDown not working

Discussion in 'Scripting' started by stevenbos655, May 3, 2020.

  1. stevenbos655

    stevenbos655

    Joined:
    May 1, 2020
    Posts:
    14
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class followMouse : MonoBehaviour
    6. {
    7.     public Transform firePoint;
    8.     public GameObject bulletPrefab;
    9.     public float bulletForce = 20;
    10.     public float offset;
    11.     private void Update()
    12.     {
    13.         Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
    14.         float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
    15.         transform.rotation = Quaternion.Euler(0f, 0f, rotZ + offset);
    16.         if (GetButtonDown("Fire1"))
    17.         {
    18.             Shoot();
    19.         }
    20.     }
    21.     void Shoot()
    22.     {
    23.         Instatiate(bulletPrefab, firePoint.position, firePoint.rotation);
    24.     }
    25. }
    26.  
     
  2. stevenbos655

    stevenbos655

    Joined:
    May 1, 2020
    Posts:
    14
    Assets\followMouse.cs(16,13): error CS0103: The name 'GetButtonDown' does not exist in the current context
     
  3. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    Did you mean Input.GetButtonDown?