Плеер несет объект. При коллизии в другом скрипте объект пропадает и появляются ошибки в инспе.
// 1 коллизия
if (col.tag == "Thing")
{
if (gameObject.tag == "fountain")
{
Destroy(fountbase);
Instantiate(probka, probkaspawn.position, Quaternion.identity);
wma.WaterStopper();
}
//2 коллизия
void OnTriggerEnter2D(Collider2D col)
{
if (col.tag == "fountain" || col.tag == "fountain2" || col.tag == "fountain3" || col.tag == "fountain4" || col.tag == "fountain5" || col.tag == "fountain6" || col.tag == "fountain7" || col.tag == "fountain8" || col.tag == "fountain9")
{
Instantiate (cover, CoverSpawner.position, Quaternion.identity);
Destroy(cover);
//здесь получается ошибка
void FixedUpdate()
{
if (Input.GetKeyDown(KeyCode.F))
{
if (!hold)
{
Physics2D.queriesStartInColliders = false;
hit = Physics2D.Raycast(transform.position, Vector2.right * transform.localScale.x, distance);
if (hit.collider != null && hit.collider.tag == "Thing")
{
hold = true;
}
}
else
{
hold = false;
if (hit.collider.gameObject.GetComponent<Rigidbody2D>() != null)
{
hit.collider.gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(transform.localScale.x, 0.3f) * throwObject;
}
}
}
if (hold)
{
hit.collider.gameObject.transform.position = holdPoint.position; //[COLOR="Red"]вот здесь ошибка[/COLOR]
if (holdPoint.position.x > transform.position.x && hold==true)
{
hit.collider.gameObject.transform.localScale = new Vector2(transform.localScale.x * 8f, transform.localScale.y * 8f);
}
else if (holdPoint.position.x < transform.position.x && hold == true)
{
hit.collider.gameObject.transform.localScale = new Vector2(transform.localScale.x * 8f, transform.localScale.y * 8f);
}
}
}