Adding and subtracting Angle problem
I want to add Angle with UpArrow and subtract it with DownArrow
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Weapon1 : MonoBehaviour
{
private bool m_FacingRight = true;
private Rigidbody2D m_Rigidbody2D;
private Vector3 m_Velocity = Vector3.zero;
public GameObject player;
private int maxAngle = 90;
private int minAngle = -90;
public float Angle;
void Start()
{
Angle = 180;
}
private void FixedUpdate()
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
Angle =+ 1 * Time.deltaTime;
}
if (Input.GetKeyDown(KeyCode.DownArrow))
{
Angle =- 1 * Time.deltaTime;
}
if (m_FacingRight)
{
Angle = Mathf.Clamp(Angle, 180-maxAngle, 180-minAngle);
transform.localRotation = Quaternion.Euler(0f, 0f, -Angle - 180f);
}
else if (!m_FacingRight)
{
Angle = Mathf.Clamp(Angle, 180-maxAngle, 180-minAngle);
transform.localRotation = Quaternion.Euler(0f, 0f, -Angle - 180f);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
How to do + or - functions to PlayerPrefs.SetInt? 1 Answer
how to displaying degrees with float ?? 1 Answer
Money not being added. 0 Answers
C# Min/Max Rotation based on Float? 1 Answer
Check rotation for a Rigidbody2D 0 Answers