Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by DragonTTK · Jun 10, 2016 at 04:14 PM · prefabtargetclone

Prefab clone to target

How would i go about this you can do it on play game but then it reverts of course im just wondering how would you go about doing this as i need to have it done for my character.

The PlayerHealth is expose to use a clone prefab.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class UIManager : MonoBehaviour
 {
 
     public PlayerHealth playerHealth;
     public Text HealthText;
 
     private static bool UIExists;
 
     // Use this for initialization
     void Start()
     {
         if (!UIExists)
         {
             UIExists = true;
             DontDestroyOnLoad(transform.gameObject);
         }
         else
         {
             Destroy(gameObject);
         }
     }
 
     // Update is called once per frame
     void Update()
     {
         HealthText.text = "" + playerHealth.currentHealth;
     }
 
 }
 
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DragonTTK · Jun 11, 2016 at 11:50 AM 0
Share

Bump can someone help thanks

avatar image Mmmpies · Jun 11, 2016 at 12:47 PM 0
Share

You'll need to change + playerHealth.currentHealth to

 HealthText.text = "" + playerHealth.currentHealth.ToString();

And telling us what's actually not working would get a better response as well. Short, concise description of what the issue is will get a much better response. As well as posting any error messages.

avatar image DragonTTK · Jun 11, 2016 at 02:13 PM 0
Share

Alright basically i have a prefab that isn't in scene until spawned (player) and i need him to be linked as a target for enemy AI to become aggressive towards but i cannot link it as target as it isn't in scene. Hope that explains more.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Mmmpies · Jun 11, 2016 at 02:24 PM

Typically you'd spawn the player first but I suppose it's up to you how you go about creating your game. There are a couple of ways of doing this.

In Update on the enemy scripts you can check if the the Player == null and if so look for it. It works but if you have a lot of enemies all looking for your player every single frame its an overhead.

You might be better having a script on the player prefab that in Start() searches for each enemy tagged object and calls a function FindPlayer to grab the newly instantiated prefab.

You need to tag each enemy and use FindGameObjectsWithTag and use a for each loop to go through each enemy and call the function to tell it to search for the player object.

This only happens once the player instantiates and is far lower as an overhead, all you need to do with the enemy script Update is

if(Player != null)

So it only tries to find/attack the player once it's instantiated.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

65 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to remove all velocity for all prefab/clone objects in the scene 1 Answer

Instantiated prefab clones don't collide like the original 2 Answers

How do I make copies of an Animated Enemy? 0 Answers

Why Original GameObject Destroy Clones ? 0 Answers

I need help destroying a clone on function. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges