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. Dismiss Notice

create object help

Discussion in 'Scripting' started by coxy17, Jul 2, 2014.

  1. coxy17

    coxy17

    Joined:
    Sep 27, 2013
    Posts:
    126
    Hi,

    I am trying to generate an object from my players current position with an offset of 2. Basically a cube appears 2 spaces infront of player upon entering a trigger.

    I have know issue with the trigger part and understand there is a create object action, but how do I get the players position over to the generated object?

    Hope I'm making sense

    Nick
     
  2. zaxvax

    zaxvax

    Joined:
    Jun 9, 2012
    Posts:
    220
  3. Patico

    Patico

    Joined:
    May 21, 2013
    Posts:
    886
    There are a lot of ways to do it. On of them bellow:

    Code (csharp):
    1.  
    2.   Vector3 placeOverPlayer = Vector3.zero;
    3.    
    4.    GameObject player = GameObject.Find("My-Player-Object-Name");
    5.    if(player != null)
    6.    {
    7.      Vector3 playerPosition = player.transform.position;
    8.      placeOverPlayer = playerPosition + Vector3.up * 2;
    9.    }
    10.    else
    11.    {
    12.      /// oops, player object was not found
    13.    }