Search Unity

Resolved The name shoot does not exits (sorry i'm newbie, i just follow some instruction on Youtube)

Discussion in 'Scripting' started by syazsyahril, May 17, 2020.

  1. syazsyahril

    syazsyahril

    Joined:
    May 17, 2020
    Posts:
    9
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class NewBehaviourScript : MonoBehaviour
    {
    private void Awake()
    {
    //Debug.Log("Inside Awake");
    }
    // Start is called before the first frame update
    void Start()
    {
    //Debug.Log("Inside Start");
    Shoot();
    }
    // Update is called once per frame
    void Update()
    {
    void Shoot()
    {
    Debug.Log("Shooting");
    }
    }
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Your Shoot() method is inside your Update() method. This makes it local only to the Update() method, and anything outside Update() cannot use it! To fix it, move Shoot() outside Update() so it is a full fledged method alongside the others:
    Code (CSharp):
    1. // Update is called once per frame
    2. void Update()
    3. {
    4. }
    5.  
    6. void Shoot()
    7. {
    8.   Debug.Log("Shooting");
    9. }
     
  3. syazsyahril

    syazsyahril

    Joined:
    May 17, 2020
    Posts:
    9
    Thanks man i appreciate it