I have this bone projectile in which I tell which direction to go through this code
if (Input.GetKey(KeyCode.LeftArrow) && Time.time > (lastFireTime + burstDelay))
{
lastFireTime = Time.time;
GameObject boneInstantiate = Instantiate(shot, shotSpawnLeft.position, shotSpawnLeft.rotation) as GameObject;
BoneScript bone = boneInstantiate.GetComponent<BoneScript>();
bone.direction.x = Mathf.Cos(270 * Mathf.Deg2Rad);
//bone.dir = 1;
//Debug.Log(bone.direction.x);
}
if (Input.GetKey(KeyCode.RightArrow) && Time.time > (lastFireTime + burstDelay))
{
lastFireTime = Time.time;
GameObject boneInstantiate = Instantiate(shot, shotSpawnRight.position, shotSpawnRight.rotation) as GameObject;
BoneScript bone = boneInstantiate.GetComponent<BoneScript>();
bone.direction.x = Mathf.Cos(90 * Mathf.Deg2Rad);
//bone.dir = 2;
//Debug.Log(bone.direction.x);
}
if (Input.GetKey(KeyCode.UpArrow) && Time.time > (lastFireTime + burstDelay))
{
lastFireTime = Time.time;
GameObject boneInstantiate = Instantiate(shot, shotSpawnUp.position, shotSpawnUp.rotation) as GameObject;
BoneScript bone = boneInstantiate.GetComponent<BoneScript>();
bone.direction.y = Mathf.Cos(0 * Mathf.Deg2Rad);
//bone.dir = 3;
//Debug.Log(bone.direction.y);
}
if (Input.GetKey(KeyCode.DownArrow) && Time.time > (lastFireTime + burstDelay))
{
lastFireTime = Time.time;
GameObject boneInstantiate = Instantiate(shot, shotSpawnDown.position, shotSpawnDown.rotation) as GameObject;
BoneScript bone = boneInstantiate.GetComponent<BoneScript>();
bone.direction.y = Mathf.Cos(180 * Mathf.Deg2Rad);
//bone.dir = 4;
//Debug.Log(bone.direction.y);
}
and then in another script I make the bone projectile move in that direction through this code
Vector3 posReference = transform.position;
Debug.Log(posReference);
posReference.x = posReference.x + bulletSpeed * direction.x * Time.deltaTime;
Debug.Log(posReference.x);
posReference.y = posReference.y + bulletSpeed * direction.y * Time.deltaTime;
Debug.Log(posReference.y);
transform.position = posReference;
The problem is the bone doesn’t move at all in that direction and it stays in the position. What am I doing wrong in this code or how should I update transform.position so the bone goes in the direction I want?