- Home /
set gamobject via script in non-Monobehaviour class?
Could someone tell me how to set a Gameobject to an existing variable public GameObject propsRoot;
via another script like with scriptableobjects
The header of the class:
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UI;
namespace KnifePlayerController
{
[System.Serializable]
public class RifleHandsController : HandsController, IWeaponAmmo, IWeaponShootMode
{
If you need more Information let me know ;)
Assu$$anonymous$$g you refer to doing it on inspector. If you want to attach it to a GameObject, your class needs to derive from Component or a class that derives from it. Else you can derive from ScriptableObject.
What do i need to change/add if i want to handle it with scriptableobejcts?
You can derive HandsController from ScriptableObject. See this tutorial
Answer by lexnewgatexyz · Jun 25, 2019 at 06:46 AM
Assume you do it in runtime, then you could use GameObject.Find
Please don't ever use GameObject.Find. This is a surefire way of tanking performance.