[Unity]2D&3D物体指向indicator鼠标,技能指示器 基础

这篇博客介绍了如何在Unity中创建2D旋转箭头跟随鼠标指向,3D物体旋转对准鼠标,以及使用Projector制作箭头投影指示器。通过设置箭头图片的Pivot和调整Projector的Rotation,可以实现灵活的指向效果。同时提到了使用Projector来制作角色技能指示器和特效圆环。
摘要由CSDN通过智能技术生成




--------------------------------------------------------------------------------------------------------------------------------------------

2D旋转箭头跟随鼠标指向的位置



参考资料1,而参考资料 2,3,4 和1 类似

准备一个 箭头图片


设置箭头的Pivot ,根据实际的箭头图片 进行设置。




using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RotateObjectToward : MonoBehaviour {
    //https://www.youtube.com/watch?v=mKLp-2iseDc
    public float speed = 5f;
   // public Transform target;
    private void Update()
    {
        //Vector2 direction = target.position - transform.position;
        Vector2 direction = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
        float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
        Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.forward);
        transform.rotation = Quaternion.Slerp(transform.rotation,rotation,speed * Time.deltaTime);
    }
}


这种旋转,方式 只是 根据 鼠标 与 该 箭头2D精灵 的 位置 ,进行偏移。

是可以随着 鼠标的移动 进行 旋转 偏移。

如果 图片没有 指向 鼠标 ,请 查看 自己 的图片 ,是否有问题。

--------------------------------------------------------------------------------------------------------------------------------------------

3D物体旋转 指向 鼠标 


参考资料 5,6



using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharacterMovement : MonoBehaviour {
    //https://www.youtube.com/watch?v=F5a4Xo6ijLE
    Rigidbody rigidBody;
    public float speed = 4;

    Vector3 lookPos;
	// Use this for initialization
	void Start () {
       
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值