- Home /
Question by
QuartzCZ · Oct 28, 2021 at 09:38 AM ·
2dgrappling gun
Why my script dont work?,Why is the script working
My script:` public class GunScript : MonoBehaviour {
public GameObject Bullet;
public float BulletSpeed;
public Transform Spot;
Vector2 Direction;
public LineRenderer line;
// Start is called before the first frame update
void Start()
{
line.enabled = false;
}
// Update is called once per frame
void Update()
{
Vector2 MousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Direction = MousePos - (Vector2)transform.position;
FaceMouse();
if (Input.GetMouseButtonDown(0))
{
Shoot();
}
if (target != null)
{
line.SetPosition(0, Spot.position);
line.SetPosition(1, target.transform.position);
}
}
void FaceMouse()
{
transform.right = Direction;
}
void Shoot()
{
GameObject BulletIns = Instantiate(Bullet, Spot.position, Quaternion.identity);
BulletIns.GetComponent<Rigidbody2D>().AddForce(transform.right * BulletSpeed);
}
public void TargetHit(GameObject hit)
{
target = hit;
line.enabled = true;
}`
and it shows me 3 times:`Nazev target v aktualnim kontextu neexistuje.` Translated:Target name does not exist in the current context.
Comment
Your answer
Follow this Question
Related Questions
2D Animation does not start 1 Answer
Why does the line not render? 0 Answers
2D grappling hook attaching to moving objects 0 Answers
Clear, Crisp pixel textures for a 2D RPG 2 Answers