Can anyone please help me?

I am following the tutorial: Junior Programmer: Create With Code 1. I am at lesson 2.2 where you make that you can shoot your food, i have the exact same code as the man in the video but for me, it doesn’t work. Can anyone help me to see what exactly doesn’t work? Here is the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FoodThrow : MonoBehaviour
{
    public float speed = 40.0f;
    public GameObject projectilePrefab;
    void Update()
    {
        if (Input.GetKeyDown (KeyCode.Space)) {
            // Launch a projectile from the player
            Instantiate(projectilePrefab, transform.position, projectilePrefab.transform.rotation);
        }
        transform.Translate(Vector3.forward * Time.deltaTime * speed);
    }
}

And if anyone can go to that tutorial and see what I did wrong, that would be very nice.

Well, first of all you could provide link for the tutorial.
Secondaly, nobody will solve your problems for you.
You should at least find what doesn’t work. Is input doesn’t work? Is projectile not spawning? Is projectile not flying towards?
Learn Debug.Log, learn IDE debugger, it will help you massively in understanding what is wrong.
If you are still struggling, at least attach images of your complete setup, your projectile prefab, its components, which scripts does it have, the projectile code etc.

1 Like

seems weird to make an object and throw yourself mind

1 Like

Hi joahhuis! Lol i have the exact same problem.

in my case the food is flying in the right direction, but eventhough i coded the script so that i can use the space bar to shoot, it just starts shooting on its own without me giving the go to. and then it just happens 1 time and the cookie is gone. actually we really should be able to “shoot” the (in my case) cookie. There is also this “destroy out of bounds” script, that makes the cookie disappear after some way on the y-achse. my thought was that these 2 scripts kind of “coolide” and the script makes the cookie disappear without coming back. normally when we shoot there should be several “clones” of the cookie. dont know what to do. so heeeelp pls :slight_smile:

Lessons 2.2 Fppd Flight

this video and its section 2 - 4 i would say.

I don’t have the destroy out of bounds script, but with me it doesn’t spawn