Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 1
fpsarmedunity

fpskit 1.6 referring to player clone

Question

Hi I'm having some issues with some scritps sincei cannot how correcly figure ho to call the player since it's spawned from gamemanager and not present in scene for start and i maded 

a scrit pthat workd fine in older fpskit but now i got an erorr relatedto the fact that player is instacianted on scene

 

Please login or register to see this code.

in this script  for example when i create the damage zone into unity i got an error due that healtscript is not found since "Player" object doesnt exist but exist player clone..any tips

Share this post


Link to post
Share on other sites

15 answers to this question

Recommended Posts


  • 0
Please login or register to see this quote.

so...can you explain me more please=?

 

 i have the same issue with some scritps i made for door intraction ..worked well on prevoius version of the kit  and now due to the player spawn ..not

Share this post


Link to post
Share on other sites
  • 0

many thanks it's worked even if for a strange reason player get damaged but helth string is not updated and when player  hit ponts reach zero player dont die LOL...

 

btw is there a way to refer the player clone directly.. i 'm only asking to learn something new...

Share this post


Link to post
Share on other sites
  • 0

you must apply damage, not set hitpoints to 0 or decrease in update

public GameObject playerref;
playerref = Instantiate (playerprefab, ...);

 

P.S. how many times i already told you to stop use kits? +1

at first you must learn c# (at least basics), so you can read and understand code.

  • Haha 1

Share this post


Link to post
Share on other sites
  • 0

thanks again OMA... i like use kits.. specificalyl your kit since throught it i learned a lot and i understand the code and i'm able to modify it and suits ti my needs LOL

 

public GameObject playerref;
playerref = Instantiate (playerprefab, ...);

 

 

and yes i know how to instantiate playerclone 

what I was asking for is how  can  i refer to it from another script and specifically acces to a script(in this case HealthScript) pf the playerClone

 

i tried this way...

in Gamemanager.cs i made playerClone public

 

public GameObject playerClone

 

i tagged Gamemanager gameobject  as "Gamemanager"

 

and i modified the DamageTrigger.cs this way

 

Please login or register to see this code.

but i got an error on game start on console

 

NullReferenceException: Object reference not set to an instance of an object
HDK_DamageTrigger.Start () (at Assets/MyScripts/Triggers/HDK_DamageTrigger.cs:25)

 

 referred t othis line of code

 

 

target = GameObject.Find("Gamemanager").GetComponent<GameManager>().playerClone;

 

i sincerly dont  know what  i missed

 

 

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

I'm using a modified template of ai fpskit 1.6 as base of my project and Yes the damage trigger scriptis fronte hdk i own

Share this post


Link to post
Share on other sites
  • 0

I dont Need to begin mate...if You or someone rose could Simply tell me how i can i correctly refer to a  script held by a clone object(in this case the player) i would bè fine

Share this post


Link to post
Share on other sites
  • 0

If you understood programming, you would know that you CAN assign a GameObject as null. So your error isn't "not finding the playerclone", your error is saying it either can't find an object tagged "Gamemanager" or a component is not attached to it called GameManager.

 

If that object and component was found, then target would be set to null and the NEXT line would throw the error, not this line. That's how you know it's an object/component finding error, not a variable setting error (unless the variable doesn't exist).

 

that is why OMA refers to start using things other than kits to start learning code, your not going to fully understand coding if you just keep modifying kits. Bc object/component finding errors are one of the first things you learn in unity

 

P.S. Not trying to be mean, just explaining why you really shouldn't use kits if you want to advance in programming

  • Like 2

Share this post


Link to post
Share on other sites
  • 0

im actually too lazy to read through all of this comments etc. but the way i would access an object spawned by another gameobject that is already in scene would be:

1) in the gamemanager class declare a global public variable of type gameobject like this: public GameObject Player = null;

2) assign sth. to it when you spawn the player like that in your gamemanager: Player = Instantiate(PlayerObject,new Verctor3(0,0,0), Quaternion.identity);

3) In the script you want to access the player from declare a global variable of type gamemanager: public gamemanager gm; //assign in inspector!!!

4) now you can access the Player through: gm.Player in the whole script: 

    if(gm.Player != 0) //tests if PlayerObject was Spawned

      {

       //Do stuff!

      }

 

Notes:

1)  just to make sure set Player back to null when the player dies /despawns /gameobject gets deletednot sure how c# takes care of this and where the addy pointing after deleting the object, so just set it to null to make sure!

2)  ofc. a better practise would be to use a gatter since you dont want to be able to set the object from outside (just dont mess with it and it ll do) 

 

  • Like 1

Share this post


Link to post
Share on other sites
  • 0

many thanks to all of you for your time and effort..and even criticism LOL

thanks to you i managed to figure how to correcly work with player spawn and even with classic player in hierarchy... 

lilltle steps ahead.. and new learned sftuffs.. LOL

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

have to agree with OMA here.

You should really watch a java or c# playlist on youtube first or sth. to get the basics down, (i liked: 

after that maybe work through the tutorial section on the unity website (Please login or register to see this link. )

(note: i didnt do the unity tutorials but even the beginner ones appear to be helpful and look like they can really teach working with unity) 

but all in all i dont have a problem with using kits but you should be able to undestand everything of the kit to really make use of it and make your own project out of it.

 

And i also dont have a problem with answering questions. Sometimes the fastest way to learn is to ask somebody who knows it (but in most scenarios this wouldnt be the case.... however when your really stuck there shouldnt be a reason not to ask)

 

well good luck and you dont have to go through all of this at once,

everybody of us is still learning and hopefully progresses every day. 

 

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...