Search Unity

help...

Discussion in 'Scripting' started by Volt777, Feb 22, 2019.

  1. Volt777

    Volt777

    Joined:
    Aug 6, 2018
    Posts:
    16
    run this script and look at the hierarchy and see why this is not good for a stealth game

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Teleport : MonoBehaviour {
    6.  
    7.     public float tpRange;
    8.  
    9.     [SerializeField]
    10.     private GameObject tpPos;
    11.     [SerializeField]
    12.     private GameObject tpOb;
    13.     private MovePlayer mp;
    14.     private bool tpModeToggle = false;
    15.     private bool tpModeCheck;
    16.  
    17.     private void Awake()
    18.     {
    19.         mp = GetComponentInParent<MovePlayer>();
    20.     }
    21.  
    22.     void Update ()
    23.     {
    24.         if (Input.GetKeyDown(KeyCode.E))
    25.         {
    26.             if(tpModeToggle == true)
    27.             {
    28.                 tpModeToggle = false;
    29.             }
    30.             else
    31.             {
    32.                 tpModeToggle = true;
    33.             }
    34.         }
    35.         if (tpModeToggle == true)
    36.         {
    37.             tpMove();
    38.         }
    39.     }
    40.     void tpMove()
    41.     {
    42.         Vector3 tpPosition = Vector3.zero;
    43.         RaycastHit hit;
    44.      
    45.  
    46.  
    47.         if (Physics.Raycast(transform.position, transform.forward,out hit)){
    48.  
    49.             GameObject tpobjclone;
    50.  
    51.             tpobjclone = Instantiate(tpOb, hit.point, hit.collider.transform.rotation);
    52.  
    53.             if(tpobjclone == null)
    54.             {
    55.                 Debug.LogError("tpobjclone Just Flunked");
    56.                 return;
    57.             }
    58.  
    59.             tpPos.transform.Rotate(Vector3.up);
    60.  
    61.             tpobjclone.transform.position = hit.point;
    62.  
    63.             tpPosition = tpPos.transform.position;
    64.         }
    65.  
    66.         /*
    67.         if (Input.GetMouseButton(0))
    68.         {
    69.             if(tpPosition == Vector3.zero)
    70.             {
    71.                 Debug.LogError("tpPosition Just Flunked");
    72.                 return;
    73.             }
    74.             mp.MovePlayerTP(tpPosition);
    75.         }
    76.         */
    77.  
    78.     }
    79. }
    I am trying to turn this into a teleport
     
    Last edited: Feb 23, 2019
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,674
    Is there a scripting problem in there you are looking to solve?
     
  3. Volt777

    Volt777

    Joined:
    Aug 6, 2018
    Posts:
    16
    In the near future...

    hey i found my solution on my own thanks