Forum rules - please read before posting.

How to get the Player object reference for the active instance.

edited April 2016 in Technical Q&A
Hi! sorry to bother you guys again. :(

I have a script that tracks the distance between the player and an object before triggering (this would allow me to start all sort of stuff automatically, when the player gets close enough, without the need for triggers). Problem is, AC's player is instantiated, and I need to pass the script the reference for the Game object (or to be precise, the transform.position from the player), so... how do you get the reference for the active player instance? :-/

I've been trying to check the scripting guide but I don't seem to be getting anywhere... so any advice would be greatly appreciated ^:)^

Comments

  • The reference you need is on the front page of the scripting guide:

    AC.KickStarter.player;

    The KickStarter script has static references for all of AC's key components, Managers included.
  • Thanks! Silly me, it was my mistake! I'd seen that one, and tried it, but I was using it wrong!

    I was trying to store it in a Gameobject variable (MyPlayer = AC.KickStarter.player;) and was getting an error.

    All had to do was ditch the variable and use the reference directly in the code: 
    Distance =(Vector3.Distance(AC.KickStarter.player.transform.position, this.transform.position))

    Again I'm sorry! As I mention I'm not much of a programmer  #:-S. I basically adapted code from an old tutorial I found on the net (http://jayanam.com/highlighting-unity-gameobjects-with-highlighter-asset/). The scripts checks the distance between an object and the player object, then activates a highlighter (or whatever you want), but also leaves a space to trigger anything when the player object is close enough (I had to make several changes to make it work..). 

    Anyways, thanks a lot. I was unsure if I was just using the wrong code, your answer helped me to rethink what I was doing!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.