E
E
Emil2019-02-02 21:49:26
C++ / C#
Emil, 2019-02-02 21:49:26

Why is the game object not being dragged to the inspector, to the script?

Good afternoon everyone, please tell me, I added character models through the unity store, and I implement the spawn of models when buying a person. I declared a public game object, threw the script on the model in Project (picture 1) 5c55e5980240f449085792.png
But for some reason I can’t drag the Cube as a game object (I take position coordinates from it) to create a spawn point. 5c55e5e09092c009986462.pngWhen I try to drag the cube, and I hover over the place in the inspector where the game object is declared in the script, just a crossed out cursor (not available). What's wrong? With others, such as 3D models, everything works great. But he doesn't want to.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Go_Go : MonoBehaviour {
    private float distance;
    public float speed;
    public GameObject spawn_transform;
    private Vector3 cube;
  // Use this for initialization
  void Start () {
        cube = spawn_transform.GetComponent<Transform>().position;
        distance = 27;
  }

    // Update is called once per frame
    void Update()
    {
        GetComponent<Transform>().position = new Vector3(cube.x, cube.y, distance);
        GetComponent<Transform>().rotation = spawn_transform.GetComponent<Transform>().rotation;
        distance = distance + speed;
        if (GetComponent<Transform>().position.z > 38.90f)
        {
            Destroy(gameObject);
          
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Gaydak, 2019-02-03
@DyadyaEmil

and you don't try to specify a link to the object from the scene in the prefab??
this is not possible)
an object from the scene can refer to prefabs.
an object from the scene can refer to another object from the scene.
but the prefab cannot refer to an object in the scene)) contradicts its basic principle of a universal blank, substituted whenever and wherever))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question