Hi, ich habe ein Problem in Unity 2D und zwar habe ich eine Arm Rotation mit der Maus gemacht, also das man mit der Maus den Arm rotieren kann. Wenn mein Spieler nach rechts guckt geht alles Normal, doch wenn der Spieler nach Links guckt geht die Steuerung überhaupt nicht, nur wenn ich mit der Maus auf der Rechten Seite von meinem Spieler bin funktioniert es ein ein wenig
weaponRotation.Angle muss ein int sein da es von einem Asset ist (Pixel Art Rotation) damit es Pixel Perfect bleibt. Wie löse ich das Problem?
|
C#-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
using UnityEngine;
using System.Collections;
using PixelArtRotation;
public class WeaponRotate : MonoBehaviour {
public Transform Weapon;
public int MaxAngle;
public int MinAngle;
private PixelRotation weaponRotation;
private Player player;
public int Angle { get; private set; }
void Start()
{
weaponRotation = Weapon.GetComponent<PixelRotation>();
player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
Angle = 0;
}
void Update()
{
RotateWeapon();
}
void RotateWeapon()
{
var pos = Camera.main.WorldToScreenPoint(Weapon.position);
var dir = Input.mousePosition - pos;
Angle = Mathf.RoundToInt(Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg);
weaponRotation.Angle = Angle;
}
}
|