Okay i have this script:
using UnityEngine;
using System.Collections;
public class PositionCheck{
public int CanMove(string direction, Vector3 position)
{
switch (direction)
{
case "up":
position.y += 1;
break;
case "down":
position.y -= 1;
break;
case "left":
position.x -= 1;
break;
case "right":
position.x += 1;
break;
}
switch (XYBlock((int)position.x, (int)position.y))
{
case 0:
return 0;
default:
break;
}
return -1;
}
int XYBlock(int xposition, int yposition)
{
if (xposition >= 0 && xposition < WC.world.GetLength(1) && yposition >= 0 && yposition < WC.world.GetLength(0))
{
return WC.world[xposition, yposition];
}
return -1;
}
}
then in player script i have this code:
PositionCheck posCheck; //this is in initialization
void Update () {
if (Input.GetKey(KeyCode.UpArrow) && canMove == true)
{
canMove = false;
if (posCheck.CanMove("up", transform.position) != -1)
{
StartCoroutine(MoveTo(transform.position, (transform.position += new Vector3(0, 1, 0)), 0.5f));
}
}
(dont worry about parsing i just copied what matters)
How can i refference PositionCheck class to call CanMove function (without making everything static and without assigning to gameobject and assign that to player)
also i plan to add other classes from position check
I just tought i fully understand classes and now this ![]()