Answer the question
In order to leave comments, you need to log in
Doesn't switch True False. What to do?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotateTank2 : MonoBehaviour
{
public Transform Selftransform;
public int speed = 6;
public bool rotate = true;
// Use this for initialization
void Start()
{
}
void RightRotate()
{
transform.Rotate(0, 0, -3);
}
void LeftRotate()
{
transform.Rotate(0, 0, 3);
}
// Update is called once per frame
void FixedUpdate()
{
if (rotate == true && !Input.GetKey(KeyCode.D))
{
RightRotate();
}
if (rotate == false && !Input.GetKey(KeyCode.D))
{
LeftRotate();
}
if (Input.GetKey(KeyCode.D))
rotate = !rotate;
Selftransform.position += Selftransform.up * speed * Time.deltaTime;
}
else
{
}
}
}
Answer the question
In order to leave comments, you need to log in
Input.GetKey(KeyCode.D)
here is the main problem. except for the hodgepodge of flags that confuse you))
read how
GetKey
GetKeyDown
GetKeyUp differs.
and understand. that GetKey - can work several times per frame.
and another important point is to do INPUT on Update (each card for responsiveness and adequacy).
not on FixedUpdate (this is for physics)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question