Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Feb 25, 2015 at 12:17 PM by fafase for the following reason:

Question is off-topic or not relevant

avatar image
0
Question by SerNoodles · Feb 25, 2015 at 12:16 PM · distanceobjectsdebugtagsoutput

Finding the distance between objects

Hi guys, sorry I know this has been asked before, I've been following the advice on the other posts but it's just not working and I can't figure out why.

I'm trying to find the distance between the current object and the player, I've assigned "PlayerTag" in the tags section to my player object and I'm trying to get the distance between the two and output it to the console. Here's my code:

 using UnityEngine;
 using System.Collections;
 
 public class EnemyController : MonoBehaviour {
     
     public float hitpoints = 100f;
     //Get player object
     GameObject player;
 
     float distance;
 
     void awake()
     {
         player = GameObject.FindGameObjectWithTag("PlayerTag");
     }
 
     void update()
     {
         //get distance between player and zombie
         distance = Vector3.Distance (gameObject.transform.position, player.transform.position);
         //output distance to console [DEBUG]
         Debug.Log ("Distance: " + distance);
     }
     
     public void RecieveDamage(float amt) 
     {
         hitpoints -= amt;
         if (hitpoints <= 0) 
         {
             Die();
         }
     }
     
     void Die() 
     {
         Destroy (gameObject);
     }
 }
 

can you guys spot what's wrong? I'm sure it's something dumb but I've been looking at it for a while now and I just don't see it.

Comment
Add comment · Show 2
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 fafase · Feb 25, 2015 at 12:17 PM 1
Share

Your update and awake should have cap letters

avatar image PixelFormedStudios · Aug 25, 2016 at 11:21 PM 0
Share

player = GameObject.FindGameObjectWithTag("PlayerTag").position;

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

distance script work with nearest tags 0 Answers

Calling 2 objects into script for onCollisionEnter? 1 Answer

Same output_log.txt file being written to by multiple clients at once? 0 Answers

When I grab an object, it is too close 1 Answer

How to detect if two objects are are near eachother? 2 Answers


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