Statwe
New member
- Joined
- Oct 1, 2022
- Messages
- 3
- Programming Experience
- Beginner
hello I was programming and I got this error
Assets\scripts\Player.cs(105,45): error CS1061: 'BulletScript' does not contain a definition for 'Direction' and no accessible extension method 'Direction' accepting a first argument of type 'BulletScript' could be found (are you missing a using directive or an assembly reference?)
Someone tell me what to do here is the code
Assets\scripts\Player.cs(105,45): error CS1061: 'BulletScript' does not contain a definition for 'Direction' and no accessible extension method 'Direction' accepting a first argument of type 'BulletScript' could be found (are you missing a using directive or an assembly reference?)
Someone tell me what to do here is the code
C#:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public GameObject bulletprefab;
public static Player obj;
public int lives = 3;
public bool isGrounded = false;
public bool isMoving = false;
public bool isImmune = false;
public float speed = 5f;
public float jumpForce = 3f;
public float movHor;
public float immuneTimeCnt = 0f;
public float immuneTime = 0.5f;
public LayerMask groundLayer;
public float radius = 0.3f;
public float groundRayDist = 0.5f;
private Rigidbody2D rb;
private Animator anim;
private SpriteRenderer spr;
void Awake()
{
obj = this;
}
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
spr = GetComponent<SpriteRenderer>();
}
// Update is called once per frame
void Update()
{
movHor = Input.GetAxisRaw("Horizontal");
isMoving = (movHor != 0f);
isGrounded = Physics2D.CircleCast(transform.position, radius, Vector3.down, groundRayDist, groundLayer);
if (Input.GetKeyDown(KeyCode.Space))
jump();
anim.SetBool("isMoving", isMoving);
anim.SetBool("isGrounded", isGrounded);
flip(movHor);
if (movHor < 0.0f) transform.localScale = new Vector3(-1.0f, 1.0f, 1.0f);
else if (movHor > 0.0f) transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
if (Input.GetKey(KeyCode.F))
{
Shoot();
}
}
void FixedUpdate()
{
rb.velocity = new Vector2(movHor * speed, rb.velocity.y);
}
public void jump()
{
if (!isGrounded) return;
rb.velocity = Vector2.up * jumpForce;
}
private void Shoot()
{
Vector3 Direction;
if (transform.localScale.x == 1.0f) Direction = Vector3.right;
else Direction = Vector3.left;
GameObject bullet = Instantiate(bulletprefab, transform.position + Direction * 0.1f, Quaternion.identity);
bullet.GetComponent<BulletScript>().SetDirection(Direction);
}
private void flip(float _xValue)
{
Vector3 theScale = transform.localScale;
if (_xValue < 0)
theScale.x = Mathf.Abs(theScale.x) * -1;
else
if (_xValue > 0)
theScale.x = Mathf.Abs(theScale.x);
transform.localScale = theScale;
}
void OnDestroy()
{
obj = null;
}
}