/// <summary> /// Returns the ghost from posessing whatever it is currently haunting to its true form. /// </summary> public void EndHaunt(GameObject overrideHauntedObject = null, bool useTransition = true, float transitionDuration = .55f) { if (haunted) { // store return position so we can raycast to it and make sure we don't cross any boundaries Vector3 destination = haunted.GetReturnPosition(); Vector3 returnPos = destination; Vector3 destinationVector = destination - transform.position; RaycastHit hit; if (Physics.CapsuleCast( transform.position, transform.position + collider.height * Vector3.up, collider.radius, destinationVector, out hit, destinationVector.magnitude, hauntReturnColliders)) { returnPos = hit.point - destinationVector.normalized * collider.radius * 1.1f; } transform.position = GhostTools.GroundPoint(returnPos); if (useTransition && GhostTools.SafeToInstantiate(gameObject)) { GameObject hauntedObject = overrideHauntedObject ? overrideHauntedObject : haunted.gameObject; SpawnTransitionObject(transform.position, hauntedObject, transitionDuration); } haunted.OnUnHaunted(); } playMaker.FsmVariables.GetFsmFloat("transitionDuration").Value = transitionDuration + hauntTransitionOffset.Value; playMaker.SendEvent("endHaunt"); haunted = null; burningCandles.Value = 0; }
void ActualPlay() { if (!GhostTools.SafeToInstantiate(gameObject)) { Debug.LogWarning("Audio playing is only supporting while game is running."); return; } if (audioCollection == null) { Debug.LogWarning(name + " has no audio connection referenced!"); return; } GameObject audioGO = new GameObject(audioCollection.name); audioGO.transform.parent = AudioParent().transform; audioGO.transform.position = transform.position; AudioSource newSource = audioGO.AddComponent <AudioSource>(); newSource.spread = 180; newSource.dopplerLevel = 0; newSource.rolloffMode = AudioRolloffMode.Linear; newSource.clip = audioCollection.GetRandomClip(); newSource.playOnAwake = false; newSource.outputAudioMixerGroup = audioCollection.mixerGroup; newSource.volume = audioCollection.volume * volume; newSource.pitch = audioCollection.Pitch(); newSource.spatialBlend = 1; newSource.maxDistance = audioCollection.maxDistance; newSource.Play(); Destroy(audioGO, audioCollection.audioLifetime); }
// left public to be accesible from Unity Events public void Instantiate() { if (!GhostTools.SafeToInstantiate(gameObject)) { return; } if (_instance != null && !allowMultipleInstances) { return; } if (ToInstantiate == null) { Debug.LogWarning(name + " has no referenced object to instantiate!", gameObject); return; } // Determine where in the hierarchy to instantiate Transform parent = null; switch (instancePlaceInHierarchy) { case HierarchyType.AsChild: parent = transform; break; case HierarchyType.AsSibling: parent = transform.parent; break; } if (!Application.isPlaying) { return; } Quaternion rotation = transform.rotation; switch (instanceRotation) { case RotationType.Prefab: rotation = ToInstantiate.transform.rotation; break; case RotationType.Zero: rotation = Quaternion.Euler(Vector3.zero); break; } _instance = Instantiate(ToInstantiate, transform.position, rotation, parent); if (applyScale) { _instance.transform.localScale = transform.localScale; } if (randomScale) { float scale = Random.Range(randomScaleRange.x, randomScaleRange.y); _instance.transform.localScale *= scale; } }
void OnDisable() { if (!toSpawn) { return; } if (GhostTools.SafeToInstantiate(gameObject)) { Instantiate(toSpawn, transform.position, transform.rotation); } }
static void GuaranteeInstance() { // Prevent objects from being spawned on un-play if (!GhostTools.SafeToInstantiate()) { return; } if (instance) { return; } instance = Instantiate(GameMaster.Get().musicPlayerPrefab).GetComponent <MusicPlayer>(); DontDestroyOnLoad(instance.gameObject); }
protected virtual void InstantiateEffect(Vector3 position) { if (!GhostTools.SafeToInstantiate(gameObject)) { return; } if (Time.unscaledTime < Mathf.Epsilon) { return; } if (_actor && _actor.culled) { return; } // If this is being disabled because we're loading a scene, we don't want it to create an effect. if (GameMaster.transitioning) { return; } if (effectPrefab == null) { Debug.LogWarning("Effect prefab is not set for " + name, gameObject); return; } if (delay > Mathf.Epsilon) { StartCoroutine(DelayedInstantiate()); } else { Destroy(Instantiate( effectPrefab, position, transform.rotation, EffectsParent().transform), lifetime); } }