Hi guys !
I want to make my own library but when I use the transform.position command for velocity I get an error. unity freezes already time.
my DLL codes:
namespace TestLDLL
{
public class Move
{
public GameObject moveObject;
public Vector3 moveVector;
public float speed;
private bool canMove = false;
public Move(GameObject moveObject, Vector3 moveVector, float speed)
{
this.moveObject = moveObject;
this.moveVector = moveVector;
this.speed = speed;
}
public void StartMove()
{
canMove = true;
while(canMove)
MoveFunc();
}
public void StopMove()
{
canMove = false;
}
private void MoveFunc()
{
moveObject.transform.position += moveVector * speed * Time.deltaTime;
}
}
}
C# Scrip Code:
public class test : MonoBehaviour {
private Move moveObject;
private Rigidbody rbody;
void Start () {
moveObject = new Move(this.gameObject, new Vector3(0f, 1f, 0f), 1f);
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
moveObject.StartMove();
}
if (Input.GetKeyDown(KeyCode.LeftShift))
{
moveObject.StopMove();
}
}
}