mirror of
https://github.com/Steffo99/keep-everything-alive.git
synced 2024-11-23 09:54:19 +00:00
24 lines
707 B
C#
24 lines
707 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
[RequireComponent(typeof(Rigidbody2D))]
|
|
public class FollowMouse : MonoBehaviour
|
|
{
|
|
private new Rigidbody2D rigidbody2D;
|
|
|
|
void Awake() {
|
|
rigidbody2D = GetComponent<Rigidbody2D>();
|
|
}
|
|
|
|
void Start() {
|
|
Vector3 screenPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
|
transform.position = new Vector3(screenPoint.x, screenPoint.y, transform.position.z);
|
|
}
|
|
|
|
void FixedUpdate()
|
|
{
|
|
Vector3 screenPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
|
rigidbody2D.MovePosition(new Vector3(screenPoint.x, screenPoint.y, transform.position.z));
|
|
}
|
|
}
|