- Home /
Question by
NumernoUno · Jul 31, 2020 at 06:30 PM ·
script.not workingclone
Script not working on clones
This is my script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Scrolling : MonoBehaviour
{
// Start is called before the first frame update
public GameObject bird;
Jumping jumping_script;
public Transform ground2;
void Awake()
{
ground2 = GetComponent<Transform>();
jumping_script = bird.GetComponent<Jumping>();
}
// Update is called once per frame
void Update()
{
if (jumping_script.gameOver == false)
{
ground2.position += Vector3.left * 0.01f;
}
}
}
and this is how I instantiate game object in other script Instantiate(obstacle, new Vector3(2.08f, -0.66f, 0.0f), Quaternion.identity);
My script is not working on clones, when gameOver == true obstacle should stop moving, but it does not. I see that script is attached to clones but is only working on original game object.
Comment
Answer by zjjc123 · Jul 31, 2020 at 07:12 PM
I'm assuming you referenced the GameObject bird in the inspector? Make sure the prefabs that you are trying to instantiate also references the same bird object.
They reference the same bird object but still no result.
No errors. This is my update function from other script
void Update()
{
if(jumping_script.gameOver == true)
{
gameover.SetActive(true);
}
scoretext.text = score.ToString();
scoretext.text = "SCORE " + score;
if (spawn == true)
{
Instantiate(obstacle, new Vector3(2.08f, -0.66f, 0.0f), Quaternion.identity);
spawn = false;
}
}