Good news! To provide faster support and grow the community, we'll be changing the forum to "Read Only" and turn to Discord instead for support.
Join here:

Teleportation Item

User avatar
Posts: 194
Joined: Mon Oct 24, 2016 10:55 pm
Location: Poland

Teleportation Item

Postby PeterBibinin » Thu Dec 01, 2016 3:56 pm

First create in scene GameObject and attach this script this will by Position Manager:

Code: Select all

using UnityEngine;
using System.Collections;

    public class MyPositionManager : MonoBehaviour
        private static MyPositionManager _instance;

        public static MyPositionManager instance
                if (_instance == null)
                    _instance = GameObject.FindObjectOfType<MyPositionManager>();

                return _instance;

        public Transform playerResetPosition;

Now create GameObject and place it somewere in scene <-- This will be place where player will be teleported.
And attach to Transform in MyPositionManager.

Now we need create custom item type:

Code: Select all

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Devdog.General;
using Devdog.InventoryPro;

   public class TeleportItem : InventoryItemBase {

    private MyPositionManager positionManager;


        public override LinkedList<ItemInfoRow[]> GetInfo()
         var basic = base.GetInfo();
         //basic.AddAfter(basic.First, new InfoBoxUI.Row[]{
         //    new InfoBoxUI.Row("Restore health", restoreHealth.ToString(),,,
         //    new InfoBoxUI.Row("Restore mana", restoreMana.ToString(),,

         return basic;

      public override void NotifyItemUsed(uint amount, bool alsoNotifyCollection)
         base.NotifyItemUsed(amount, alsoNotifyCollection);


      public override int Use()
         int used = base.Use();
         if (used < 0) // Whoops! Anything below 0 is a failed action.
            return used;

         if (currentStackSize <= 0)
            return -2;
        // Do something specific...

   // Teleport player
        var player = PlayerManager.instance.currentPlayer;
        player.transform.position = MyPositionManager.instance.playerResetPosition.position;
        player.transform.rotation = MyPositionManager.instance.playerResetPosition.rotation;

        // Do something with item, this will remove item from inventory
        currentStackSize--; // Remove 1

         NotifyItemUsed(1, true);
         return 1; // 1, the item was used, but no items were used (stack decrease) in the process

have fun ;] :)
Waiting for sunrise
Try make world beter ;]

My Advanced Save System tutorial with screen capture like in The Forest !
Advanced Save System

Return to “Share custom components”

Who is online

Users browsing this forum: No registered users and 1 guest