Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question How to declare a body to a moving platform?

Discussion in 'Game Design' started by Party_Rocker, Dec 5, 2022.

  1. Party_Rocker

    Party_Rocker

    Joined:
    Nov 4, 2022
    Posts:
    6
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class StickyPlatform : MonoBehaviour
    {
    private void OnCollisionEnter(Collision collision);

    if (Collision.gameObject.name == "Player")
    {
    collision.gameObject.transform.SetParent(transform);
    }
    private void OnCollisionExit(Collision collision)
    {
    if (collision.gameObject.name =="Player")
    {
    collision.gameObject.transform.SetParent(null);
    }
    }