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. Dismiss Notice

Question Help got this error my script name is "Bulletf"

Discussion in 'Scripting' started by yanferstudios, Aug 4, 2023.

Thread Status:
Not open for further replies.
  1. yanferstudios

    yanferstudios

    Joined:
    Aug 3, 2023
    Posts:
    4
    Assets\johnsa.cs(63,29): error CS0246: The type or namespace name 'Bulletf' could not be found (are you missing a using directive or an assembly reference?)







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

    public class johnsa : MonoBehaviour
    {
    public GameObject BulletPrefab;
    public float Speed;
    public float JumpForce;

    private Rigidbody2D Rigidbody2D;
    private Animator Animator;
    private float horizontal;
    private bool Grounded;
    void Start()
    {
    Rigidbody2D = GetComponent<Rigidbody2D>();
    Animator = GetComponent<Animator>();
    }


    void Update()
    {
    horizontal = Input.GetAxisRaw("Horizontal");

    if (horizontal < 0.0f) transform.localScale = new Vector3(-1.0f, 1.0f, 1.0f);
    else if (horizontal > 0.0f) transform.localScale = new Vector3(1.0f, 1.0f);


    Animator.SetBool("running", horizontal != 0.0f);

    Debug.DrawRay(transform.position, Vector3.down * 0.1f, Color.red);

    if (Physics2D.Raycast(transform.position, Vector3.down, 0.1f))
    {
    Grounded = true;
    }
    else Grounded = false;
    if (Input.GetKeyDown("w") && Grounded)
    {
    Jump();
    }
    if (Input.GetKey("space"))


    Shoot();

    }

    private void Jump ()
    {
    Rigidbody2D.AddForce(Vector2.up * JumpForce);
    }

    private void Shoot()

    {
    Vector3 direction;
    if (transform.localScale.x == 1.0f) direction = Vector2.right;
    else direction = Vector3.left;

    GameObject bullet = Instantiate(BulletPrefab, transform.position + direction * 0.1f, Quaternion.identity);
    bullet.GetComponent<Bulletf>().SetDirection(direction);
    }
    private void FixedUpdate()
    {
    Rigidbody2D.velocity = new Vector2(horizontal, Rigidbody2D.velocity.y);
    }
    }
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,900
    - please use CODE tags on the forums when you post code, details are here
    - what is your question exactly? Do you have a
    Bulletf
    class? Should you have a
    Bulletf
    class? Is it a typo and it should be
    Bullet
    instead? We don't know, you know your project
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    Lurking-Ninja likes this.
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    Please don't make any more posts without using code-tags.

    Thanks.
     
Thread Status:
Not open for further replies.