【问题标题】:Scaling two gameobject simultaneously [duplicate]同时缩放两个游戏对象[重复]
【发布时间】:2021-02-19 12:06:05
【问题描述】:

我有两个游戏对象,基本上我希望在将两个对象缩放在一起然后移动之后将两个对象一起移动。是否可以更改它们然后移动它们以及如何做到这一点?任何方法将不胜感激。

【问题讨论】:

    标签: c# unity3d 3d augmented-reality gameobject


    【解决方案1】:

    为了清楚起见;你想根据其他一些对象的比例来改变对象的值吗?如果是这样,当您更改对象的比例时,触发C# Event 并在您想要更改值的类中订阅它。这是示例:

    public class ScaleChangingClass
    {
        Vector3 scale;
    
        // Create event argument to pass changed scale to another class
        public class OnScaleChangedEventArgs : EventArgs
        {
            public Vector3 scale;
        }
        // create event with event args
        public static event EventHandler<OnScaleChangedEventArgs> OnScaleChanged;
    
        void ChangeScale()
        {
            // Change Scale;
            // Fire the event ?.Invoke ensure if no class subscribe, it won't throw any error
            OnScaleChanged?.Invoke(this, new OnScaleChangedEventArgs() { scale = scale });
        }
    }
    
    public class SecondClass : MonoBehaviour
    {
        private void Awake()
        {
            ScaleChangingClass.OnScaleChanged += ScaleChangingClass_OnScaleChanged;
        }
    
        private void ScaleChangingClass_OnScaleChanged(object sender, ScaleChangingClass.OnScaleChangedEventArgs e)
        {
            var changedScale = e.scale;
            // Scale changed do the thing
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2019-02-24
      • 1970-01-01
      • 1970-01-01
      • 2020-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      相关资源
      最近更新 更多