Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何为阵列中的每个游戏对象设置检查器选项? 使用系统集合; 使用System.Collections.Generic; 使用UnityEngine; 公共类SpinObject:单行为 { 私有布尔减速=假; 公众浮标轮换速度; 公共浮动缓慢下降最大值; 公众持股比例缓慢下降; 公共游戏对象[]对象旋转; //用于初始化 无效开始() { } //每帧调用一次更新 无效更新() { for(int i=0;i慢降最大值) 减速=真; 否则如果(旋转速度_C#_Unity3d_Unity5 - Fatal编程技术网

C# 如何为阵列中的每个游戏对象设置检查器选项? 使用系统集合; 使用System.Collections.Generic; 使用UnityEngine; 公共类SpinObject:单行为 { 私有布尔减速=假; 公众浮标轮换速度; 公共浮动缓慢下降最大值; 公众持股比例缓慢下降; 公共游戏对象[]对象旋转; //用于初始化 无效开始() { } //每帧调用一次更新 无效更新() { for(int i=0;i慢降最大值) 减速=真; 否则如果(旋转速度

C# 如何为阵列中的每个游戏对象设置检查器选项? 使用系统集合; 使用System.Collections.Generic; 使用UnityEngine; 公共类SpinObject:单行为 { 私有布尔减速=假; 公众浮标轮换速度; 公共浮动缓慢下降最大值; 公众持股比例缓慢下降; 公共游戏对象[]对象旋转; //用于初始化 无效开始() { } //每帧调用一次更新 无效更新() { for(int i=0;i慢降最大值) 减速=真; 否则如果(旋转速度,c#,unity3d,unity5,C#,Unity3d,Unity5,我有一组游戏对象:GameObject[] 我想在inspector中为每个游戏对象设置选项,这样当我更改选项时,它将影响到游戏对象,而不是所有游戏对象 每次我都会添加一个新的gmaeobject,我想为他提供一些选项。我想要么使用类,要么使用简单的结构: using System.Collections; using System.Collections.Generic; using UnityEngine; public class SpinObject : MonoBehaviour {

我有一组游戏对象:GameObject[] 我想在inspector中为每个游戏对象设置选项,这样当我更改选项时,它将影响到游戏对象,而不是所有游戏对象


每次我都会添加一个新的gmaeobject,我想为他提供一些选项。

我想要么使用类,要么使用简单的结构:

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

public class SpinObject : MonoBehaviour
{
    private bool slowDown = false;
    public float rotationSpeed;
    public float slowdownMax;
    public float slowdownMin;
    public GameObject[] objectsToRotate;

    // Use this for initialization
    void Start ()
    {

    }

    // Update is called once per frame
    void Update ()
    {
        for (int i = 0; i < objectsToRotate.Length; i++)
        {
            if (rotationSpeed > slowdownMax)
                slowDown = true;
            else if (rotationSpeed < slowdownMin)
                slowDown = false;

            rotationSpeed = (slowDown) ? rotationSpeed - 0.1f : rotationSpeed + 0.1f;
            objectsToRotate[i].transform.Rotate(Vector3.forward, Time.deltaTime * rotationSpeed);
        }
    }
}
[System.Serializable]
公共结构SpinableObject
{
公共交通;
公众浮标轮换速度;
公共浮动速度;
公共浮动最大速度;
公共浮动汇率;
[hideininstecpt]
公共利益减速;
}
公共类SpinObject:单行为
{
私有布尔减速=假;
公众浮标轮换速度;
公共浮动缓慢下降最大值;
公众持股比例缓慢下降;
公共游戏对象[]对象旋转;
//每帧调用一次更新
无效更新()
{
for(int i=0;ispinableObject.maxSpeed)
spinableObject.slook=true;
else if(spinableObject.rotationSpeed
我不知道你想用哪个选项,我可能做了一些到很多。但是如果你想使用那么多的选项,我会使用一个类和它自己的函数来管理旋转,另一个类来指示对象是加速还是减速

[System.Serializable]
public struct SpinableObject
{
    public Transform t ;
    public float rotationSpeed ;
    public float minSpeed ;
    public float maxSpeed ;
    public float speedRate;
    [HideInInspector]
    public bool slowDown ;
}

public class SpinObject : MonoBehaviour
{
    private bool slowDown = false;
    public float rotationSpeed;
    public float slowdownMax;
    public float slowdownMin;
    public GameObject[] objectsToRotate;

    // Update is called once per frame
    void Update ()
    {
        for (int i = 0; i < objectsToRotate.Length; i++)
        {
            SpinableObject spinableObject = objectsToRotate[i]

            if (spinableObject.rotationSpeed > spinableObject.maxSpeed )
                spinableObject.slowDown = true;
            else if (spinableObject.rotationSpeed < spinableObject.minSpeed )
                spinableObject.slowDown = false;

            spinableObject.rotationSpeed = (spinableObject.slowDown) ? spinableObject.rotationSpeed - 0.1f : spinableObject.rotationSpeed + 0.1f;
            spinableObject.t.Rotate(Vector3.forward, Time.deltaTime * spinableObject.rotationSpeed);
        }
    }
}
[System.Serializable]
公共类SpinableObject
{
[序列化字段]
私有变换t;
[序列化字段]
私人浮动旋转速度;
[序列化字段]
私人浮动速度;
[序列化字段]
私有浮点最大速度;
[序列化字段]
私人浮动汇率;
私人股本增长放缓;
公共空间(英文)
{
如果(旋转速度>最大速度)
减速=真;
否则如果(旋转速度<分钟速度)
减速=错误;
旋转速度=(减速)?旋转速度-0.1f:旋转速度+0.1f;
t、 旋转(Vector3.forward、Time.deltaTime*旋转速度);
}
}
公共类SpinObject:单行为
{
私有布尔减速=假;
公众浮标轮换速度;
公共浮动缓慢下降最大值;
公众持股比例缓慢下降;
公共SpinableObject[]objectsToRotate;
//每帧调用一次更新
无效更新()
{
for(int i=0;i
如果您能向我展示如何使用类/es进行此操作的示例,请?关于这个解决方案,我得到了一个错误:SpinableObject SpinableObject=objectsToRotate[i];错误在:objectsToRotate[i]无法将类型“UnityEngine.GameObject”隐式转换为“SpinableObject”好的,我现在看到了您的编辑。现在,我在行中遇到错误:objectsToRotate[i].Rotate();'“GameObject”不包含“Rotate”的定义,并且找不到接受“GameObject”类型的第一个参数的扩展方法“Rotate”(是否缺少using指令或程序集引用?)。我在声明
objectsToRotate
时出错,请检查我的更新答案:
public SpinableObject[]对象旋转而不是
公共游戏对象[]对象旋转现在它正在工作。我还有一个问题。在更新中加入循环(FOR)是件好事吗?(因为该函数在每一帧调用,并且for循环将在每一帧激活,从而大幅降低fps)。也许应该有一些,如果有或其他什么?不要担心,一个简单的for循环不会使你的FPS下降。除非数组中有一千个对象。
[System.Serializable]
public class SpinableObject
{
    [SerializeField]
    private Transform t ;
    [SerializeField]
    private float rotationSpeed ;
    [SerializeField]
    private float minSpeed ;
    [SerializeField]
    private float maxSpeed ;
    [SerializeField]
    private float speedRate;
    private bool slowDown ;

    public void Rotate()
    {
        if (rotationSpeed > maxSpeed )
            slowDown = true;
        else if (rotationSpeed < minSpeed )
           slowDown = false;

        rotationSpeed = (slowDown) ? rotationSpeed - 0.1f : rotationSpeed + 0.1f;
        t.Rotate(Vector3.forward, Time.deltaTime * rotationSpeed);
    }
}

public class SpinObject : MonoBehaviour
{
    private bool slowDown = false;
    public float rotationSpeed;
    public float slowdownMax;
    public float slowdownMin;
    public SpinableObject[] objectsToRotate;

    // Update is called once per frame
    void Update ()
    {
        for (int i = 0; i < objectsToRotate.Length; i++)
        {
            objectsToRotate[i].Rotate();
        }
    }
}