A
A
Almaz_20202020-02-05 16:20:10
C++ / C#
Almaz_2020, 2020-02-05 16:20:10

Missing using directive or c# assembly reference?

using System.Collections.Generic;
using UnityEngine;

public class MovePlayer : MonoBehavior
{
public Transform player;
[SerializeField]
private float speed = 10f;
private void OnMouseDrag()
{
if (!player. lose )ERROR
{
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
mousePos.x = mousePos.x > 2.5f ? 2.5f : mousePos.x;
mousePos.x = mousePos.x < -2.5f ? -2.5f : mousePos.x;
player.position = Vector2.MoveTowards(player.position,
new Vector2(mousePos.x, player.position.y), speed * Time.deltaTime);
}
}

}
ERROR, code for Unity
Missing using directive or assembly reference !

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Gaydak, 2020-02-05
@MrMureno

Let's try to learn and explain)))
Here is your code from the comments to another answer (to make it clearer what other people are talking about)

public class player : MonoBehaviour
{
public static bool lose = false;
private void OnTriggerEnter2D(Collider2D other) {
if (other.gameObject.tag == "bomb")
lose = true;
}

Now to the point.
In principle, a static variable can be accessed through the
ClassName.VariableName
WITHOUT any object references, that's why it is static.
But you have
a variable and a class named the same (not to mention the fact that the classes should be named with a capital)
//public Transform player;
public  SomeClassName someObjectRef;
//////
//bool flagFromStatic = player.lose;
bool flagFromStatic = SomeClass.staticVariableInClass;
bool flagFromClassObject = someObjectRef.nonStaticVariableInClass;

in general, it is clearly required to study the BASICS of the language and programming as such.
good luck

G
GavriKos, 2020-02-05
@GavriKos

Transform has no lose field in principle. So either player must not be Transform, or there must be not lose.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question