尝试在Unity中创建随机Vector3

您所在的位置:网站首页 unity随机生成对象 尝试在Unity中创建随机Vector3

尝试在Unity中创建随机Vector3

2023-11-09 15:41| 来源: 网络整理| 查看: 265

我试图创建一个随机范围,但是Unity给我这个错误: UnityException: Vector3不允许从MonoBehaviour构造函数(或实例字段初始化器)中调用,而是在唤醒或启动中调用它。从MonoBehavior调用,名为'particleMover‘。这是我的代码:

using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using UnityEngine; public class particleMover : MonoBehaviour { public float moveSpeed; public float temperature; public Rigidbody rb; public Transform tf; static private float[] directions; // Start is called before the first frame void Start() { System.Random rnd = new System.Random(); float[] directions = { rnd.Next(1, 360), rnd.Next(1, 360), rnd.Next(1, 360) }; } // Update is called once per frame void Update() { Vector3 direction = new Vector3(directions[0], directions[1], directions[2]); direction = moveSpeed * direction; rb.MovePosition(rb.position + direction); } }


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3