- Home /
 
               Question by 
               SavageX370 · Dec 09, 2018 at 04:18 PM · 
                materialinventorylistsscriptable objectitems  
              
 
              PLEASE HELP! How can I add the material component from this scriptable object to a public list? My goal is to allow the player to apply materials to game objects from that list.
//Application of materials from List to gameobjects script works!!
     using System.Collections;
     using System.Collections.Generic;
     using UnityEngine;
     
     public class AddOnClick : MonoBehaviour
     {
         public Material[] materials;
         public RaycastHit hit;
         public Ray ray;
         Renderer rend;
     
         void Start()
         {
             rend = GetComponent<Renderer>();
             rend.enabled = true;
         }
     
         void Update()
         {
             if (Input.GetMouseButtonDown(0))
             {
                 ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                 if (Physics.Raycast(ray, out hit, 100) && hit.collider.gameObject.tag == "Temperament")
                 {
                     Debug.Log(materials);
                     rend.sharedMaterial = materials[0];
     
                 }
             }
     
         }
     }
     
//But I can't add the material from the ScriptableObject to that list!!
     using System.Collections;
     using System.Collections.Generic;
     using UnityEngine;
     
     [CreateAssetMenu(fileName = "New Item", menuName = "Inventory/Item")]
     public class Item : ScriptableObject
     
     {
         new public string name = "New Item";
         public Sprite icon = null;
         public bool isDefaultItem = false;
         public Material prefab;
         public List<Material> materials;
         public virtual void Use()
         {
             Debug.Log("Using" + name);
             addtoArray(prefab);
     
         }
     
         public void RemoveFromInventory()
         {
     
         }
     
         void addtoArray(Material obj)
         {
             prefabs.Add(obj);
         }
     }
 
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                