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
0
Question by swagae · Jul 29, 2012 at 04:53 AM · aienemyhorrorlooking

Is the Player Being Looked at

Hello, I am new to unity and not very experienced. Currently I've been trying to make a horror game and I want to make it so that the enemy does and action (attacks) if you look at it (in your screen view). Please give advice if you know how to do thins in C#.

                                 THANKS!!! :)
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 OperationDogBird · Jul 29, 2012 at 05:08 AM 0
Share

what type of view is it? if it is first person view you can use something like

//On Enemy

 if(renderer.isVisible)//Do something

there are many ways to do it, this is probly the quickest to write and understand. The isVisable will be true if the enemy is being rendered by ANY camera in the scene(this includes the scene camera if you dont have $$anonymous$$aximize On Play enabled and are viewing the enemy), so if there are more than one camera the results will most likely not be what you want

avatar image Seth-Bergman · Jul 29, 2012 at 05:18 AM 0
Share

if it's first person (as it seems to be by your description) the above suggestion is easiest..

also note that even the objects shadow being visible is enough to return true here..

http://docs.unity3d.com/Documentation/ScriptReference/Renderer-isVisible.html

and also keep in $$anonymous$$d this works even in the editor, not just in playmode

avatar image swagae · Jul 29, 2012 at 05:21 AM 0
Share

OperationDogBird, I tried the example you give and it seems promising, however, it say that my 3d model does not have a "renderer" attached to it, how do I add one?

And yes, it is first person. Thank you for the advice.

avatar image OperationDogBird · Jul 29, 2012 at 05:26 AM 0
Share

Sorry for the spelling error, good catch Seth. The model should have a renderer attached bcz otherwise you cant see it. click the prefab in the scene and view its components in the inspector, there should be a component called $$anonymous$$esh Renderer. If not(which is hard to believe) you can add from the top bar of unity- Component/$$anonymous$$esh/$$anonymous$$esh Renderer.

avatar image OperationDogBird · Jul 29, 2012 at 05:43 AM 1
Share

I did think of this, tho a better solution is to just have all the meshes parented to the main mesh and not an empty object. also this portion

 var the$$anonymous$$odel[] : Renderer;

wont work, you need to exclude the [] part of the declaration(unless theres some secret C# thing i dont know about). If you wanted to get components, the correct type would be

var childrenR : Renderer[];

Then you can access the individual ones by using indexing.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by cupsster · Aug 02, 2012 at 09:35 AM

More propper solution would be to test enemy bounding box center position against view cone. Some vector math library was posted on wiki which does this calculus.

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

8 People are following this question.

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

Related Questions

Need an enemy script that makes him wander and detect 1 Answer

Need help with my enemy spawn script. 1 Answer

free roaming enemy ai 1 Answer

Make enemy appear in front of player and then disappear at random times 2 Answers

Enemy AI problems 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