Tanoda
LinearReferenceSpawner.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using System.Collections;
10using System.Collections.Generic;
11using UnityEngine;
12
13namespace Leap.Unity.Examples {
14
22 [AddComponentMenu("")]
23 public class LinearReferenceSpawner : MonoBehaviour {
24
26 public GameObject toSpawn;
27
28 public float forwardSpawnMultiplier = 1F;
29 public Vector3 spawnOffset = Vector3.left * 1.5F;
30
31 private GameObject _spawnedObj;
32
33 void Update() {
34 bool justSpawned = false;
35 if (_spawnedObj == null) {
36 _spawnedObj = GameObject.Instantiate(toSpawn);
37 justSpawned = true;
38 }
39
40 if (justSpawned
41 || (_spawnedObj.transform.position - spaceship.transform.position).z < -1F) {
42 setSpawnPosition();
43 if (justSpawned) _spawnedObj.transform.position += Vector3.forward * 2F;
44 }
45 }
46
47 private void setSpawnPosition() {
48 Vector3 spawnPos = spaceship.transform.position;
50 spawnPos += spawnOffset;
51 _spawnedObj.transform.position = spawnPos;
52 }
53
54 public void Respawn() {
55 setSpawnPosition();
56 }
57
58 }
59
60}
This script keeps a GameObject in front of the ship, off to the side a bit. The skybox cannot provide...
The spaceship in this example is a kinematic rigidbody with a force API, but having a rigidbody on yo...
Definition: Spaceship.cs:33