同时缩放两个游戏对象
Scaling two gameobject simultaneously
我有两个游戏对象,基本上我希望在将两个对象一起缩放然后移动之后将两个对象一起移动。是否可以更改它们然后移动它们以及如何做到这一点?任何方法将不胜感激。
为清楚起见;你想根据其他一些对象的比例来改变对象的值吗?如果是这样,当您更改对象的比例时,触发 C# Event 并在您想要更改值的 class 中订阅它。这是示例:
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
}
}
我有两个游戏对象,基本上我希望在将两个对象一起缩放然后移动之后将两个对象一起移动。是否可以更改它们然后移动它们以及如何做到这一点?任何方法将不胜感激。
为清楚起见;你想根据其他一些对象的比例来改变对象的值吗?如果是这样,当您更改对象的比例时,触发 C# Event 并在您想要更改值的 class 中订阅它。这是示例:
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
}
}