コード例 #1
0
        private void OnTriggerEnter(Collider other)
        {
            // we need the deployment barrier because the rope is not long enough for the magnet to reach the ground
            //Log.Debug("Magnet.OnTriggerEnter: " + other.gameObject.name);
            DeploymentBarrier barrier  = other.gameObject.GetComponent <DeploymentBarrier>();
            Dropzone          dropzone = other.gameObject.GetComponent <Dropzone>();

            if (barrier != null && carriedCrate == null)
            {
                movement.UnscaledVelocity = Vector3.up;
                OnCraneDeploymentReturning?.Invoke(scene.Game, new CraneEventArgs());
            }

            else if (dropzone != null && carriedCrate != null)
            {
                carriedCrate.isInDropzone = true;
                scene.CratesInDropzone++;
            }
        }
コード例 #2
0
        private void HandleCollision(Floor floor)
        {
            // if a crate is carried by the crane and the floor is a dropzone, drop the crate
            if (carriedCrate != null)
            {
                //Debug.Log("Crane: Detaching crate: " + carriedCrate);

                // add a rigidbody to the crate to make it react to physics
                carriedCrate.gameObject.AddComponent <Rigidbody>();

                // detach the crate
                Crate crate = carriedCrate;
                carriedCrate.transform.parent = carriedCrate.CrateHub;
                carriedCrate = null;
                OnCrateDropped?.Invoke(scene.Game, new CrateEventArgs(crate.id, crate.isInDropzone));
            }

            // in any case: move the crane upwards
            movement.UnscaledVelocity = Vector3.up;
            OnCraneDeploymentReturning?.Invoke(scene.Game, new CraneEventArgs());
        }
コード例 #3
0
        private void HandleCollision(Crate crate)
        {
            // suppress collisions with the carried crate (this should never happen)
            if (crate == carriedCrate)
            {
                Log.Warn("Magnet: Collision with carried crate (this should not have happened and could mean that the program is broken)");
                return;
            }

            // if no other crate is carried by the crane, pick it up
            if (carriedCrate == null)
            {
                //Debug.Log("Magnet: Attaching crate: " + crate.name);

                // remove the crate's rigidbody to make it not react to physics on its own and forward collisions to the crane
                Destroy(crate.GetComponent <Rigidbody>());

                // attach the crate
                crate.transform.parent = this.transform;
                carriedCrate           = crate;
                if (carriedCrate.isInDropzone)
                {
                    carriedCrate.isInDropzone = false;
                    scene.CratesInDropzone--;
                    OnCratePickedUp?.Invoke(scene.Game, new CrateEventArgs(crate.id, true));
                }
                else
                {
                    OnCratePickedUp?.Invoke(scene.Game, new CrateEventArgs(crate.id, false));
                }
            }

            // in any case: move the crane upwards
            movement.UnscaledVelocity = Vector3.up;
            OnCraneDeploymentReturning?.Invoke(scene.Game, new CraneEventArgs());
        }