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 /
avatar image
-1
Question by Alanj2007 · Nov 06, 2013 at 03:04 PM · playerrange

Something happen when object near player?

Hey, do you know how to make something happen when an object near the player? It's like a slender game. When slender near the player, static appear

The object is enemy

Comment
Add comment · Show 7
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 mattssonon · Nov 06, 2013 at 03:15 PM 0
Share

Put a collider on the object, make it a trigger, increase the size to whatever you'd like, check for the object's name in OnTriggerEnter().

avatar image Alanj2007 · Nov 06, 2013 at 03:18 PM 0
Share

That's not gonna work because the object is enemy. If I put a collider in it, and increase the size. Player would die suddenly with nothing happen.

avatar image mattssonon · Nov 06, 2013 at 03:20 PM 0
Share

That's only because you've scripted it that way.

avatar image Huacanacha · Nov 06, 2013 at 03:26 PM 1
Share

Easiest way to do this is to add a script to the object with a reference to the player and check for the object being within certain radius of the player. In FixedUpdate() check for:

 (transform.position - player.transform.position).magnitude < activationDistance

Where activationDistance defines the radius, or activation threshold. You can distance on an axis by only checking the x,y or z distance.

If you need something more accurate, for example something that takes into account the player and object shapes, then you'll probably want to use some type of trigger collider as mentioned by mattssonon.

avatar image Alanj2007 · Nov 06, 2013 at 03:34 PM 0
Share

I will try study Vector and $$anonymous$$agnitude. I don't learn it yet :P

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by drod7425 · Nov 06, 2013 at 03:19 PM

If you want the static effect from the slender game, you might want to check the distance and increase the static as the object gets closer to the player.

Vector3.Distance - http://docs.unity3d.com/Documentation/ScriptReference/Vector3.Distance.html

Comment
Add comment · Show 7 · 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
avatar image Alanj2007 · Nov 06, 2013 at 03:21 PM 0
Share
 var other : Transform;
     if (other) {
         var dist = Vector3.Distance(other.position, transform.position);
         print ("Distance to other: " + dist);
     }

other : Transform << I should put enemy in here right?

avatar image drod7425 · Nov 06, 2013 at 03:23 PM 1
Share

If that script is on the player, yes.

avatar image Alanj2007 · Nov 06, 2013 at 03:25 PM 0
Share

Yes, I attach it to Player. Thanks. Wait, how do I manage the distance?

avatar image drod7425 · Nov 06, 2013 at 03:27 PM 1
Share

What do you mean? The Distance returns a float to the dist variable. Use that variable to increase/decrease your static. I don't know how you're doing that, so I can't really comment on that.

avatar image drod7425 · Nov 06, 2013 at 03:41 PM 2
Share

You might want to do some program$$anonymous$$g tutorials. The simplest way would be:

 if(dist<static$$anonymous$$inimumDistance){
 //start the static
 }

Personally, I'd have a movie texture that played static and I'd change the texture's alpha inversely to the distance.

Show more comments

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

18 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Assigning varaibles to prefabs 1 Answer

Clarification on how RangeAttribute works 1 Answer

MouseButtonDown on button (Far away) NEED: Range for button 2 Answers

2D Player Spawn Issue 0 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