Как сделать, чтобы сфера смотрела и двигалась туда куда и камера и вращалась при этом?
Код игрока:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class Player : MonoBehaviour
{
private float speed = 10f;
private bool isGrounded;
private float JumpForce = 150f;
private float money = 0f;
private Rigidbody _rb;
public TMP_Text moneyText;
public GameObject youLose;
void Start()
{
_rb = GetComponent<Rigidbody>();
}
void Update()
{
moneyText.text = "You have:" + money.ToString() + "$";
}
void FixedUpdate()
{
Move();
Jump();
}
void Move()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0f, moveVertical);
_rb.AddForce(movement * speed);
}
void Jump()
{
if (Input.GetAxis("Jump") > 0)
{
if (isGrounded)
{
_rb.AddForce(Vector3.up * JumpForce);
}
}
}
private void OnCollisionEnter(Collision other)
{
if (other.gameObject.tag == "Ground")
{
isGrounded = true;
}
}
private void OnCollisionExit(Collision other)
{
if (other.gameObject.tag == "Ground")
{
isGrounded = false;
}
}
}
если надо и скрипт камера:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraAroundPlayer : MonoBehaviour
{
public Transform target;
public Vector3 offset;
public float sensitivity = 3;
public float limit = 80;
public float zoom = 0.25f;
public float zoomMax = 10;
public float zoomMin = 3;
private float X, Y;
void Start()
{
limit = Mathf.Abs(limit);
if (limit > 90)
{
limit = 90;
}
offset = new Vector3(offset.x, offset.y, -Mathf.Abs(zoomMax) / 2);
transform.position = target.position + offset;
}
void Update()
{
if (Input.GetAxis("Mouse ScrollWheel") > 0)
{
offset.z += zoom;
}
else if (Input.GetAxis("Mouse ScrollWheel") < 0)
{
offset.z -= zoom;
}
offset.z = Mathf.Clamp(offset.z, -Mathf.Abs(zoomMax), -Mathf.Abs(zoomMin));
X = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivity;
Y += Input.GetAxis("Mouse Y") * sensitivity;
Y = Mathf.Clamp(Y, -limit, limit);
transform.localEulerAngles = new Vector3(-Y, X, 0);
transform.position = transform.localRotation * offset + target.position;
}
}