Quantcast
Channel: Questions in topic: "parenting"
Viewing all articles
Browse latest Browse all 302

Player exits don't destroy on load because of moving platform

$
0
0
Hi ! I am working on my first game as an intern, and I need a quick fix because my game has to be done by tonight... So I have a don't destroy on load script that works fine unless my player touches a moving platform, making him a child of said platform. When he gets down from the platform, he is no longer child of the platform but is still out of the don't destroy on load... How can I put him back in there to keep on playing other scenes? Here's my moving platform script;> Blockquote using System.Collections; using System.Collections.Generic; using UnityEngine; public class Platform : MonoBehaviour { public float speed; public Transform pos1, pos2; public Transform startPos; Vector3 nextPos; public Transform player; public Transform sightStart, sightEnd; private GameObject target = null; private Vector3 offset; private void Start() { target = null; nextPos = startPos.position; } void OnCollisionEnter2D(Collision2D col) { col.gameObject.transform.SetParent(gameObject.transform, true); } void OnCollisionExit2D(Collision2D col) { col.gameObject.transform.parent = null; } void OnTriggerStay2D(Collider2D col) { target = col.gameObject; offset = target.transform.position - transform.position; } void OnTriggerExit2D(Collider2D col) { target = null; } void Update() { if(transform.position == pos1.position) { nextPos = pos2.position; } if (transform.position == pos2.position) { nextPos = pos1.position; } transform.position = Vector3.MoveTowards(transform.position, nextPos, speed*Time.deltaTime); } private void OnDrawGizmos() { Gizmos.DrawLine(pos1.position, pos2.position); } } >

Viewing all articles
Browse latest Browse all 302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>