- Home /
call a another scripts function from a prefab
When I try to assign an object with the proper script, it won't allow me to add it to the prefab (I even tried to link to link before it was a prefab) unless the game object i'm linking is itself a prefab
this is causing a problem because the function only runs on the clone, not the prefab
SCRIPT B
![using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class CardStats : MonoBehaviour
{
public Deck deck;
public int cardCost;
public int cardHealth;
public int cardDefense;
public Text cardHealthText;
public Text cardCostText;
public Text cardDefenseText;
public int cardID;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (cardCost <= 0)
{
cardCost = 0;
}
if (cardHealth <= 0)
{
cardHealth = 0;
}
if (cardDefense <= 0)
{
cardDefense = 0;
}
if (Input.GetKeyDown(KeyCode.D))
{
cardID = deck.tempDeck[0];
Debug.Log(" Huh? " + cardID);][1]
[1]: /storage/temp/94415-deck-snip-1.png
As Prefabs exist outside of scenes, they can only reference other non-scene assets.
Check out the manual on Prefabs here: https://docs.unity3d.com/$$anonymous$$anual/Prefabs.html
Why not set up your object in the scene?
Answer by shadowpuppet · May 19, 2017 at 01:36 PM
sorry, not an answer just a commiseration. I find prefabs a slippery slope. I made an enemy a prefab for respawning but when respawned his waypoints were missing ( for patroling) so i had to make the waypoints prefabs as well...which opened another can of worms.I also discovered I need to drag the prefab waypoints into the enemies gameObject variable slot from the prefabs folder, NOT from the scene hierarchy
Your answer
![](https://koobas.hobune.stream/wayback/20220612122343im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to reference a prefab to the script that doesn't exist in Hierarchy 0 Answers
Easily reference class instance 1 Answer
I have a problem whit a script and prefabs 2 Answers
C'# When Taking Variables From Other Scripts, The Values Do Not Update 1 Answer
NullReferenceException: Object reference not set to an instance of an object 1 Answer