I want to use transform command on my own library
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();
}
}
}
Comment
Answer by Jessespike · Aug 26, 2016 at 06:56 PM
There's an infinite loop.
while(canMove)
MoveFunc();
canMove can never be set to false, because execution gets stuck in a loop calling MoveFunc
Your answer
Follow this Question
Related Questions
Unity crashing with runtime error, when accessing opencv function in unity. [HELP]!!! 1 Answer
[SOLVED] Copying assembly from 'Temp/....dll' to 'Library/...' failed (project stucked) 0 Answers
Using RuntimeInitializeOnLoadMethod inside dll and using in iOS build 1 Answer
Cinemachine (or the unity compiler) broken due to some unknown reason 1 Answer