Answer the question
In order to leave comments, you need to log in
Will the script added to the prefab be common to all objects created by this prefab?
Green - prefab, Red - objects created using the prefab.
The object itself, created using it:
Script code in the prefab:
using UnityEngine;
using System.Collections;
public class UpWall : MonoBehaviour {
public Transform camer;
public camera cam;
private Transform pointDistans;
private float distans;
public float distansSpawn = 12f;
public float speedUp = 5f;
private float count;
public GameObject[] barriers;
// Use this for initialization
void Start () {
pointDistans = GameObject.Find("point").GetComponent<Transform>();
count = transform.position.y + 41f;
int rand = (int)Mathf.Round(Random.Range (0, barriers.Length));
Debug.Log (rand);
GameObject inst = Instantiate (barriers[rand]);
inst.transform.parent = transform;
inst.transform.position = transform.position;
distansSpawn += cam.speed / 5f;
}
// Update is called once per frame
// Высчитывает расстояние от барьера до камеры при нужном расстоянии, подымает его.
void FixedUpdate () {
distans = Vector3.Distance (pointDistans.position, camer.position);
//Debug.Log (distans);
//Debug.Log (transform.position.y);
if (distans <= distansSpawn)
{
if(transform.position.y <= count)
{
transform.Translate(new Vector3(0,41f,0) * speedUp * Time.deltaTime);
}
}
}
}
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