如何解决当我的子弹被击中时,如何为我的子弹添加旋转?
我有一段时间没有使用轮换,所以我不记得如何做到这一点。我正在尝试为我的子弹制作一个随机轨迹,我想添加一个随机旋转,但我不知道如何添加旋转。我在脚本中评论了应该添加旋转的地方。我曾尝试添加 0 -> [{'green': [{'name': 'apple'},{'price': 'good'},'random string'],'red': [{'name': 'strawberry'},'another random string',{'price': 'high'}]},'final random string',{'yellow': [{'name': 'peach'},{'price': 'bad at winter'}]}]
1 -> {'green': [{'name': 'apple'},{'price': 'high'}]}
2 -> [{'name': 'apple'},'random string']
3 -> {'name': 'apple'}
4 -> apple
None
,但出现错误 + transform.rotation * Quaternion.Euler(0,rot,0)
。我可以添加什么来完成这项工作?
error CS0019: Operator '+' cannot be applied to operands of type 'Vector3' and 'Quaternion'
解决方法
我会研究 transform.rotation.RotateAround
函数。有了这个,你可以调用你的子弹的相对向前,并基本上围绕自身旋转
代码如下:
using UnityEngine;
//Attach this script to a GameObject to rotate around the target position.
public class Example : MonoBehaviour
{
//Assign a GameObject in the Inspector to rotate around
public GameObject target;
void Update()
{
// Spin the object around the target at 20 degrees/second.
transform.RotateAround(target.transform.position,Vector3.up,20 * Time.deltaTime);
}
}
这是文档的 URL:https://docs.unity3d.com/ScriptReference/Transform.RotateAround.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。