var speed = rigidbody.velocity.magnitude;
speed *= 3.6f;
var speed = rigidbody.velocity.magnitude*3.6f;
[SerializeField]private GameObject player;
[SerializeField] private float speed=2f;
private Camera camera => Camera.main;
private bool isMove;
private Vector3 targetPosition;
private void Update()
{
if (Input.GetMouseButton(0))
{
targetPosition = camera.ScreenToWorldPoint(Input.mousePosition);
targetPosition.z = 0;
isMove = true;
}
if (isMove)
{
player.transform.position =
Vector3.Lerp(player.transform.position, targetPosition, Time.deltaTime * speed);
if ((targetPosition-player.transform.position).sqrMagnitude < 0.1f)
{
isMove = false;
}
}
}
private GameObject player;
private float oldSqrMagnitude;
private Camera camera => Camera.main;
private void Update()
{
var newSqrMagnitude = (player.transform.position - camera.ScreenToWorldPoint(Input.mousePosition)).sqrMagnitude;
if (newSqrMagnitude > oldSqrMagnitude)
{
Debug.Log("дальше");
}
else if (newSqrMagnitude < oldSqrMagnitude)
{
Debug.Log("ближе");
}
else
{
Debug.Log("стоит");
}
oldSqrMagnitude = newSqrMagnitude;
}
private void OnCollisionStay(Collision other)
{
go = other.gameObject;
if (!go.CompareTag("Player"))
return;
Attack();
}
private void Attack()
{
if (gameEntity.isEnemyAttack)
{
gameEntity.isEnemyAttack = false;
gameEntity.basicEnemy.Cooldown = cooldown;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Управление : MonoBehaviour
{
Rigidbody2D rb;
Animator anim;
void Start()
{
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
}
if (Input.GetAxis("Horizontal") == 0)
{
anim.SetInteger("stay", 1);
}
else
{
Flip();
anim.SetInteger("stay", 2);
}
}
void Flip()
{
if (Input.GetAxis("Horizontal") < 0)
transform.localRotation = Quaternion.Euler(0, 0, 0);
if (Input.GetAxis("Horizontal") > 0)
transform.localRotation = Quaternion.Euler(0, 180, 0);
}
void FixedUpdate()
{
rb.velocity = new Vector2(Input.GetAxis("Horizontal") * 12f, rb.velocity.y);
}
void jump()
{
rb.AddForce(transform.up * 14f, ForceMode2D.Impulse);
}
}