using UnityEngine;
public class Bullet : MonoBehaviour
{
private Rigidbody2D rb;
private float speed = 7f;
void Start()
{
rb = GetComponent<Rigidbody2D>();
rb.velocity = transform.right * speed; // Используем velocity для движения пули
Destroy(gameObject, 3f); // Уничтожаем пулю через 3 секунды (на ваше усмотрение)
}
}
using UnityEngine;
public class Bullet : MonoBehaviour
{
private Rigidbody2D rb;
private float speed = 7f;
void Start()
{
rb = GetComponent<Rigidbody2D>();
rb.AddForce(transform.right * speed, ForceMode2D.Impulse); // Используем AddForce для движения пули
Destroy(gameObject, 3f); // Уничтожаем пулю через 3 секунды (на ваше усмотрение)
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float camSens = 0.25f;
private Vector3 lastMouse = Vector3.zero;
private Rigidbody rb;
public float speed = 6.0f;
void Awake()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
Vector3 mouseDelta = Input.mousePosition - lastMouse;
float mouseX = mouseDelta.x * camSens;
float mouseY = -mouseDelta.y * camSens;
lastMouse = Input.mousePosition;
Vector3 currentRotation = transform.rotation.eulerAngles;
currentRotation.y += mouseX;
transform.rotation = Quaternion.Euler(currentRotation);
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
Vector3 moveDirection = new Vector3(horizontalInput, 0, verticalInput).normalized;
moveDirection = transform.TransformDirection(moveDirection);
Vector3 newPosition = rb.position + moveDirection * speed * Time.deltaTime;
rb.MovePosition(newPosition);
if (Input.GetKey("space"))
{
transform.position = Vector3.zero;
}
}
}