Hi guys…I have a problem with with a return in my code…
this is my code…everything is okay but CoinMove method doesn’t return 1 and return 0…
my code is in the pic
public class Cube : MonoBehaviour
{
[SerializeField] float xVelocitySpeed = 5f;
[SerializeField] float yVelocitySpeed = 0f;
Rigidbody2D cubeRigidbody;
[SerializeField] GameObject cubeStarterPrefab;
[SerializeField] float cubeDelayToMove;
private bool ImIn = false;
public int CoinsPlusOne = 0;
// Start is called before the first frame update
void Start()
{
cubeRigidbody = GetComponent<Rigidbody2D>();
CoinMove();
}
// Update is called once per frame
void Update()
{
Invoke("MoveCubes", cubeDelayToMove);
//if (Input.GetButtonDown("Fire1"))
//{
// analyzer();
//}
analyzer();
}
public void MoveCubes()
{
cubeRigidbody.velocity = new Vector2(xVelocitySpeed, yVelocitySpeed);
}
void OnTriggerEnter2D(Collider2D wall)
{
if(wall.name == "in")
{
ImIn = true;
}
else if(wall.name == "out")
{
ImIn = false;
}
else
{
DestroyObject(gameObject);
}
}
public void analyzer()
{
if(ImIn == true && gameObject.tag == "WhiteCubes")
{
CoinsPlusOne += 1;
ImIn = false;
}
else if(ImIn == true && gameObject.tag != "WhiteCubes")
{
return;
}
else
{
return;
}
}
public int CoinMove()
{
return CoinsPlusOne;
}
}