В значительной степени то, что говорится в названиях. После добавления этого сценария к персонажу моего игрока:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotateHit : MonoBehaviour
{
public string Tag;
public float offset;
private Transform target;
private Vector3 targetPos;
private Vector3 thisPos;
private float angle;
void Start()
{
target = GameObject.FindGameObjectWithTag(Tag).GetComponent<Transform>();
}
void LateUpdate()
{
targetPos = target.position;
thisPos = transform.position;
targetPos.x = targetPos.x - thisPos.x;
targetPos.y = targetPos.y - thisPos.y;
angle = Mathf.Atan2(targetPos.y, targetPos.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle + offset));
}
}
Каждый раз, когда я нажимаю клавишу прыжка, звучит звуковой эффект, но он не двигается. Если это имеет значение, я пытаюсь приложить силу к жесткому телу 2D, чтобы заставить их прыгать.
Мой код перехода:
if (m_Grounded && jump)
{
m_Grounded = false;
m_Rigidbody2D.AddForce(new Vector2(0f, m_JumpForce));
}
bool jump = false;
if (Input.GetButtonDown("Jump"))
{
jump = true;
FindObjectOfType<AudioManager>().Play("Jump");
}
Код разделен, потому что каждая часть находится в другой компонент.