Answer the question
In order to leave comments, you need to log in
Unity object reference given to script in Editor not saved?
In short:
I have a checkpoint script (1) and a script that saves certain values (2). From 1, the respawn coordinates come to 2. In the checkpoint in the inspector, I referred to 2, but on startup the link flies, and None is written in the link to 2 column (Bottom of the photo).
Now in more detail:
using UnityEngine;
public class checkpointScr : MonoBehaviour
{
private bool opened = false;
//data это то, что нам нужно
public dataScript data;
public BoxCollider2D mycollider;
public PolygonCollider2D playercollider;
public SpriteRenderer spriteRenderer;
public Sprite newSprite;
public Light Light1;
public Light Light2;
AudioSource mySounding;
public AudioClip mySound;
void Start()
{
data = GetComponent<dataScript>();
mySounding = GetComponent<AudioSource>();
Light1.intensity = 0;
Light2.intensity = 0;
}
void Update()
{
if (mycollider.IsTouching(playercollider) && opened == false)
{
Light1.intensity = 1;
Light2.intensity = 1;
opened = true;
mySounding.PlayOneShot(mySound, 0.9f);
spriteRenderer.sprite = newSprite;
//здесь скрипт передаёт координаты
data.x = gameObject.transform.position.x;
data.y = gameObject.transform.position.y - 1.6f;
data.z = gameObject.transform.position.z;
}
}
}
using System.Collections.Generic;
using UnityEngine;
public class dataScript : MonoBehaviour
{
//тут совсем пусто
public float x = -3.01f, y = -1.73f, z = 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question