went i create a prefab the scrip assign in that prefab disappear event went i click applied a hundred time
- and after deleting and recreating sometime a message appear in the output saying Cyclic nesting detected
Prefabs are assets meant to use in the same way in every scene possible.
Because of that, you can’t assign a reference of a GameObject in a particular scene.
The only thing you can do to keep those references in the prefab is to make the gameObject that has ‘Score’ and ‘BallMovement’ as child of Bumper, but that’s not too smart in this case.
Another workaround (that can be the best) is to use the ‘Score’ and ‘BallMovement’ as a Singleton and at the start of the BumperScript you get those references.
Last one, go with tags. Tag the Score gameObject with the tag ‘Score’ and with a simple
void Start()
{
Score = GameObject.FindWithTag("Score");
}
But i really suggest you to use the Singleton pattern.
Have a great dev-time!
Thanks but its doesn’t work because
“Score” and “BallMovement” are script
I reference the scripts because i want to read or change variable in those other script
here the bumper script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BumperScript : MonoBehaviour
{
public Animator animator;
public Score score;
public BallMovement BallMovement;
public int Bumper_State = 0;
public float CooldownTime = 60;
private float TimeLeft;
void Start()
{
TimeLeft = CooldownTime;
}
// Update is called once per frame
void Update()
{
animator.SetInteger("Bumper_State", Bumper_State);
if (Bumper_State == 0 & TimeLeft > 0)
{
score.AddPoints(1);
TimeLeft = CooldownTime;
}
else
{
TimeLeft--;
}
}
void OnCollisionEnter2D(Collision2D collision)
{
if (BallMovement.GameStart == true)
{
Bumper_State++;
}
}
}