сделай джостик для вращение игрока
- User
сделай джостик для вращение игрока
- Assistant
- User
сделай джостик для вращения игрока using System.Collections; using System.Collections.Generic; using Terresquall; using UnityEngine;
public class PlayerMovement : StaticInstance { public float speed = 5f; private Camera mainCamera; public VirtualJoystick JoystickMove; public VirtualJoystick JoystickRotate;
private void Start() { mainCamera = Camera.main; } public Vector3 GetWorldPositionOnPlane(Vector3 screenPosition, float y) //получить координату?? { Ray ray = mainCamera.ScreenPointToRay(screenPosition); //?? Plane groundPlane = new Plane(Vector3.up, new Vector3(0, y, 0)); //?? if (groundPlane.Raycast(ray, out float distance)) { return ray.GetPoint(distance); } return Vector3.zero; } // Update is called once per frame void Update() { Vector3 movementJoystick = new Vector3(JoystickMove.axis.x, 0, JoystickMove.axis.y); // создали переменную, для инпутов transform.Translate(movementJoystick * speed * Time.deltaTime, Space.World); // меняем трансформ // почему транслейт?? и как растет число?? // привязали к импут менеджеру в настройках проекта к джостику Vector3 cursorWorldPosition = GetWorldPositionOnPlane(Input.mousePosition, transform.position.y); //позици мыши Vector3 forward = cursorWorldPosition - transform.position; forward.y = 0; if (forward.magnitude>0.1f) { transform.rotation = Quaternion.LookRotation(forward); } Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); // создали переменную, для инпутов transform.Translate(movement * speed * Time.deltaTime,Space.World); // меняем трансформ // почему транслейт?? и как растет число?? } - Assistant
- User
раздели логику для телефона и компьютера // Update is called once per frame void Update() {
Vector3 movementJoystick = new Vector3(JoystickMove.axis.x, 0, JoystickMove.axis.y); // создали переменную, для инпутов transform.Translate(movementJoystick * speed * Time.deltaTime, Space.World); // меняем трансформ // почему транслейт?? и как растет число?? // Вращение Vector3 forwardJoystick = new Vector3(JoystickRotate.axis.x, 0, JoystickRotate.axis.y); if (forwardJoystick.magnitude > 0.1f) { transform.rotation = Quaternion.LookRotation(forwardJoystick); } // привязали к импут менеджеру в настройках проекта к джостику Vector3 cursorWorldPosition = GetWorldPositionOnPlane(Input.mousePosition, transform.position.y); //позици мыши Vector3 forward = cursorWorldPosition - transform.position; forward.y = 0; if (forward.magnitude>0.1f) { transform.rotation = Quaternion.LookRotation(forward); } Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); // создали переменную, для инпутов transform.Translate(movement * speed * Time.deltaTime,Space.World); // меняем трансформ // почему транслейт?? и как растет число?? } - Assistant
- User
сделай автоматическую стрельбу раз в секунду using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerShooting : MonoBehaviour { public GameObject projectilePrefab; public Transform firePoint; public float projectileSpeed = 25f;
// Start is called before the first frame update void Start() { } public void Shoot() { GameObject projectile = Instantiate(projectilePrefab, firePoint.position, Quaternion.identity); Rigidbody rb = projectile.GetComponent<Rigidbody>(); rb.AddForce(transform.forward* projectileSpeed,ForceMode.VelocityChange ); } // Update is called once per frame void Update() { return; if (Input.GetButtonDown("Fire1")) { Shoot(); } }}
- Assistant