- Home /
Question by
dragonplant2006 · Apr 04, 2021 at 08:34 AM ·
c#unity 2d
Input.mousePoition for controllers
I'm making a top-down 2d shooter game, and I'm trying to add local multiplayer. my problem is that both players should be able to aim but only the mouse controls the aiming and that is because of the Input.mousePosition (I think). if there is a way to change it I would appreciate your answer.
here's the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PTwoGun : MonoBehaviour
{
public GameObject Player;
// Update is called once per frame
private void FixedUpdate()
{
Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
difference.Normalize();
float rotationZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0f, 0f, rotationZ);
if (rotationZ < -90 || rotationZ > 90)
{
if (Player.transform.eulerAngles.y == 0)
{
transform.localRotation = Quaternion.Euler(180, 0, -rotationZ);
}
else if (Player.transform.eulerAngles.y == 180)
{
transform.localRotation = Quaternion.Euler(180, 180, -rotationZ);
}
}
}
}
Comment