Я хочу свойства объекта из одного скрипта использовать в другом. При этом скрипты находятся на разных объектах.
Хочу public GameObject Object;(допустим туда поставил point light) из одного скрипта , в другом скрипте задать ему другой цвет. Но почему-то не получается
И можно как-то избавить от перетаскивания объекта в _uiPanel;
Синтаксис:
Используется csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HellTwo : MonoBehaviour
{
public GameObject Object;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
using System.Collections.Generic;
using UnityEngine;
public class HellTwo : MonoBehaviour
{
public GameObject Object;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
Синтаксис:
Используется csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HellOne : MonoBehaviour
{
[SerializeField]
private GameObject _uiPanel;
private HellTwo _levelScript;
private void Start()
{
_levelScript = _uiPanel.GetComponent<HellTwo>();
}
public void SomeMethod()
{
_levelScript.Object = new Color(1f, 2f, 3f);
}
}
using System.Collections.Generic;
using UnityEngine;
public class HellOne : MonoBehaviour
{
[SerializeField]
private GameObject _uiPanel;
private HellTwo _levelScript;
private void Start()
{
_levelScript = _uiPanel.GetComponent<HellTwo>();
}
public void SomeMethod()
{
_levelScript.Object = new Color(1f, 2f, 3f);
}
}