Question by
Mattthhdp · May 24, 2017 at 08:19 PM ·
rotationcursormousepositionweapon
Rotate weapon with the crossair and cursor lock
So i have 3 scripts the first one is
public class PlayerCrosshairs : MonoBehaviour
{
public Transform anchor;
public float maxMoveRadius;
public float sensitivity = 1f;
Vector3 position = Vector2.zero;
private void Update()
{
CrossairLocation();
}
public void CrossairLocation()
{
Vector3 moveDelta = new Vector3(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"), 0);
position = Vector3.ClampMagnitude(position + moveDelta * sensitivity, maxMoveRadius);
transform.position = anchor.position + position;
}
}
I assign in the inspector the "crossair" the max range and the anchor and it is working fine.
my second script is
public class CursorManager : MonoBehaviour
{
public static bool isLocked;
private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
public void CursorLocked(bool isLocked)
{
if (isLocked)
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
if (!isLocked)
{
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
}
}
}
Who is also working fine, it lock the cursor so i only see the crossair in the first script. the probleme is in the next script
i want the weapon of my 2d sprite to also follow the crossair (a gun) but i cannot seem to find how to use the crossair.rotation to follow the weapon.rotation (i have try several thing and none of them is working
public class PlayerWeaponManager : MonoBehaviour
{
PlayerCrosshairs thePlayerCrosshairs;
private float rotate;
private void Start()
{
rotate = transform.position.z;
}
// Update is called once per frame
void Update()
{
// rotate = transform.position.z;
// rotate = thePlayerCrosshairs.CrosshairLocation();
}
}
sorry for my bad english im french.
Comment