2D platformer Help

Updated on August 5, 2014 in [A] 2D
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
6 on August 3, 2014

I got to the part in Brackeys “how to make a 2D Platformer” 8B, were i had to exit monodevelop and test out what we just coded. i was wondering if you could help me solve this error i got. “the name ‘shoot’ does not exist in the current context”

I thought i coded exactly what he did and he got no errors. PLESE HELP!!!!   

  • Liked by
Reply
0 on August 3, 2014

make sure you have a function called shoot() in your code 🙂 else try to paste the code here so we can see whats going on

  • Liked by
Reply
Cancel
1 on August 3, 2014

I understand that i may need a function, but i followed his video tutorial EXACTLY how he did it. The only difference is he got no errors with the same exact code. he is the code i wrote. It looks a little messeed up because of the small window space.

using UnityEngine;
using System.Collections;

public class Weapons : MonoBehaviour {

public float FireRate = 0;
public float Damage = 10;
public LayerMask NotToHit;

float TimeToFire = 0;
Transform FirePoint;

// Use this for initialization
void Awake () {
FirePoint = transform.FindChild (“FirePoint”);
if (FirePoint == null) {
Debug.LogError (“NO FIREPOINT? WHAT”);
}
}

// Update is called once per frame
void Update () {
if (FireRate == 0) {
if (Input.GetButtonDown (“Fire1”)) {
Shoot();
}
} else {
if (Input.GetButton (“Fire1”) && Time.time > TimeToFire){
TimeToFire = Time.time + 1/FireRate;
Shoot();
}
}
}

void shoot () {
Debug.Log (“Test”);

}
}

on August 3, 2014

you can always use [ code ] [/ code ] tags (without the spaces) to indent your code 😛

and btw the function you call should match the name of the initial functions name 😛 ie you have void shoot() and you’re calling Shoot(); ^^ try to see if that fixes it (your shoot function isnt capitalized)

Show more replies
  • Liked by
Reply
Cancel
0 on August 3, 2014

adding void got rid of the two origanal errors but added 4 more!

  • Liked by
Reply
Cancel
0 on August 3, 2014

sorry for wasting your time. The ‘Shoot’ should not have a capital ‘S’. thanks for you assistance!!

  • Liked by
Reply
Cancel
0 on August 5, 2014

I had the same problem, with the same solution. Don’t consider it a waste of time…. it helped me a lot that you asked!! 😀

  • Liked by
Reply
Cancel