private void OnTriggerEnter(Collider other) { if (other.tag == "Player") { transformVariable.RuntimePosition = transform.position; transformVariable.RuntimeRotation = transform.rotation.eulerAngles; transformVariable.RuntimeScale = transform.localScale; if (spawnPoint == null) { GameObject gameObject = GameObject.FindGameObjectWithTag("PlayerSpawn"); if (gameObject == null) { return; } spawnPoint = gameObject.GetComponent <vp_SpawnPoint>(); if (spawnPoint == null) { return; } } spawnPoint.transform.position = transform.position; spawnPoint.transform.Rotate(transform.rotation.eulerAngles); saveObject.SaveData(); if (zone != null && zoneManager != null) { zoneManager.SetZone(zone.zone); } Debug.Log("SavePoint::Zone = " + zone.zone); playerInside = true; } }
public static vp_Placement GetRandomPlacement(float physicsCheckRadius, string tag) { // abort if scene contains no spawnpoints if ((SpawnPoints == null) || (SpawnPoints.Count < 1)) { return(null); } // fetch a random spawnpoint vp_SpawnPoint spawnPoint = null; if (string.IsNullOrEmpty(tag)) { spawnPoint = GetRandomSpawnPoint(); } else { spawnPoint = GetRandomSpawnPoint(tag); if (spawnPoint == null) { spawnPoint = GetRandomSpawnPoint(); Debug.LogWarning("Warning (vp_SpawnPoint --> GetRandomPlacement) Could not find a spawnpoint tagged '" + tag + "'. Falling back to 'any random spawnpoint'."); } } // if no spawnpoint was found, revert to world origin if (spawnPoint == null) { Debug.LogError("Error (vp_SpawnPoint --> GetRandomPlacement) Could not find a spawnpoint" + (!string.IsNullOrEmpty(tag) ? (" tagged '" + tag + "'") : ".") + " Reverting to world origin."); return(null); } // found a spawnpoint! use it to create a placement return(spawnPoint.GetPlacement(physicsCheckRadius)); }
/// <summary> /// /// </summary> protected virtual void Start() { if (PhotonNetwork.connected) { Debug.LogWarning("Warning (" + this + ") This script should not be used when connected. Disabling self. (Did you forget to disable a vp_MPSinglePlayerTest object in a multiplayer map?)"); enabled = false; return; } PhotonNetwork.offlineMode = true; vp_Gameplay.IsMultiplayer = false; vp_Gameplay.IsMaster = true; vp_PlayerEventHandler[] players = FindObjectsOfType <vp_PlayerEventHandler>(); foreach (vp_PlayerEventHandler player in players) { vp_Utility.Activate(player.gameObject, false); } vp_MPMaster[] masters = Component.FindObjectsOfType <vp_MPMaster>() as vp_MPMaster[]; foreach (vp_MPMaster g in masters) { if (g.gameObject != gameObject) { vp_Utility.Activate(g.gameObject, false); } } // disable demo gui via globalevent since we don't want hard references // to code in the demo folder vp_GlobalEvent.Send("DisableMultiplayerGUI", vp_GlobalEventMode.DONT_REQUIRE_LISTENER); vp_SpawnPoint p = vp_SpawnPoint.GetRandomSpawnPoint(); switch (m_SpawnMode) { case SpawnMode.Prefab: GameObject l = (GameObject)GameObject.Instantiate(LocalPlayerPrefab, p.transform.position, p.transform.rotation); l.GetComponent <vp_PlayerEventHandler>().Rotation.Set(p.transform.eulerAngles); break; case SpawnMode.Scene: vp_Utility.Activate(LocalPlayerPrefab, true); if (p != null) { LocalPlayerPrefab.transform.position = p.transform.position; LocalPlayerPrefab.GetComponent <vp_PlayerEventHandler>().Rotation.Set(p.transform.eulerAngles); } break; } }
/// <summary> /// snaps the player to a placement decided by the specified spawnpoint, taking into /// account the spawnpoint's radius, ground snap and random rotation settings. if the /// player has a vp_Respawner component, its 'ObstructionRadius' setting will be used /// for obstruction checking. otherwise the obstruction radius will be 1 meter. /// </summary> public static void Teleport(vp_SpawnPoint spawnPoint) { if (spawnPoint == null) { return; } float obstructionRadius = ((m_Respawner != null) ? m_Respawner.ObstructionRadius : 1.0f); vp_Placement placement = spawnPoint.GetPlacement(obstructionRadius); Position = placement.Position; Rotation = placement.Rotation.eulerAngles; Stop(); }
/// <summary> /// /// </summary> private void OnEnable() { m_Component = (vp_SpawnPoint)target; }
public static vp_Placement GetRandomPlacement(float physicsCheckRadius, string tag) { // abort if scene contains no spawnpoints if ((SpawnPoints == null) || (SpawnPoints.Count < 1)) { return(null); } // fetch a random spawnpoint vp_SpawnPoint spawnPoint = null; if (string.IsNullOrEmpty(tag)) { spawnPoint = GetRandomSpawnPoint(); } else { spawnPoint = GetRandomSpawnPoint(tag); if (spawnPoint == null) { spawnPoint = GetRandomSpawnPoint(); Debug.LogWarning("Warning (vp_SpawnPoint --> GetRandomPlacement) Could not find a spawnpoint tagged '" + tag + "'. Falling back to 'any random spawnpoint'."); } } // if no spawnpoint was found, revert to world origin if (spawnPoint == null) { Debug.LogError("Error (vp_SpawnPoint --> GetRandomPlacement) Could not find a spawnpoint" + (!string.IsNullOrEmpty(tag) ? (" tagged '" + tag + "'") : ".") + " Reverting to world origin."); return(null); } // found a spawnpoint! set placement position to that of // the spawnpoint and apply horizontal spawnpoint radius // offset (if any) vp_Placement p = new vp_Placement(); p.Position = spawnPoint.transform.position; if (spawnPoint.Radius > 0.0f) { Vector3 newPos = (Random.insideUnitSphere * spawnPoint.Radius); p.Position.x += newPos.x; p.Position.z += newPos.z; } // stay clear of other physics blockers and snap to ground if (physicsCheckRadius != 0.0f) { if (!vp_Placement.AdjustPosition(p, physicsCheckRadius)) { return(null); } vp_Placement.SnapToGround(p, physicsCheckRadius, spawnPoint.GroundSnapThreshold); } // if spawnpoint is set to use random rotation - create one. // otherwise use the rotation of the spawnpoint if (spawnPoint.RandomDirection) { p.Rotation = Quaternion.Euler(Vector3.up * Random.Range(0.0f, 360.0f)); } else { p.Rotation = spawnPoint.transform.rotation; } return(p); }