Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class shauldspading : MonoBehaviour
- {
- public Transform Player;
- public Transform Mouse;
- // Use this for initialization
- void Start ()
- {
- }
- // Update is called once per frame
- void FixedUpdate ()
- {
- //var mousePos = Input.mousePosition;
- //Vector3 Mouse = Camera.main.ScreenToWorldPoint(mousePos);
- float xTo, yTo;
- Vector3 pos = transform.position;
- xTo = Player.position.x + lengthdir_x(Mathf.Min(9,Vector3.Distance(Player.transform.position, Mouse.transform.position)), Mouse.position);
- yTo = Player.position.y + lengthdir_y(Mathf.Min (9, Vector3.Distance (Player.transform.position, Mouse.transform.position)), Mouse.position);
- pos.x += (xTo - pos.x) / 25;
- pos.y += (yTo - pos.y) / 25;
- transform.position = pos;
- }
- float lengthdir_x(float len, Vector3 dir)
- {
- dir = dir.normalized * len;
- return dir.x;
- }
- float lengthdir_y(float len, Vector3 dir)
- {
- dir = dir.normalized * len;
- return dir.y;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment