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 hotozi · Nov 08, 2012 at 04:47 PM · gameobjecttransformtrigger

My script doesnt respond what i wrote HELP!!!

Tell Me whats wrong with my script? cuz i dont get it... because the hole script work but the variable targetted always equal true when a gameobject is in the trigger, it doesnt repect the distance to set true or false the var targeted...see by your own....i did not put the variables list...but i think u can get it ....because there are so many i dont want mix up your mind...well....does repect what i wrote so... HELP PLZZ.. oh and the transform and the object that it supose to seee are rigidbodies....

function Update(){

if(!ObTarget==null)

{Objectdistance=Vector3.Distance(ObTarget.transform.position,Owner.position);}

if(!BObTarget==null)

{BObjectdistance=Vector3.Distance(ObTarget.transform.position,Owner.position);}

if(!Crate==null)

{CrateDistance=Vector3.Distance(ObTarget.transform.position,Owner.position);}

if(Crate==null&&ObTarget==null&&BObTarget==null){Targeted=false;} }

/

function OnTriggerStay(Hitting:Collider){

///////////OBJECTS

if(Hitting.gameObject.name=="Mine(Clone)"||Hitting.gameObject.name=="Mine")

{Crate=Hitting.gameObject; if(CrateDistance<4){Targeted=true;} if(CrateDistance>4{Targeted=false;}}

/

if(Hitting.gameObject.name=="Rocket(Clone)"||Hitting.gameObject.name=="Detonator Bomb(Clone)"||Hitting.gameObject.name=="Detonator Grenade(Clone)")

{ObTarget=Hitting.gameObject; if(Objectdistance<8){Targeted=true;}if(Objectdistance>8){ObTarget=null;Targeted=false;}}

/

if(Hitting.gameObject.tag=="Explosion")

{BObTarget=Hitting.gameObject; if(BObjectdistance<8{Targeted=true;}if(BObjectdistance>8){BObTarget=null;Targeted=false;}} }

/

/

function OnTriggerExit(Hitting:Collider) {

////////////OBJECTS

if(Hitting.gameObject.name=="Mine(Clone)"||Hitting.gameObject.name=="Mine"){Crate=null;Targeted=false;}

if(Hitting.gameObject.name=="Rocket(Clone)"||Hitting.gameObject.name=="Detonator Bomb(Clone)"||Hitting.gameObject.name=="Detonator Grenade(Clone)")

{ObTarget=null;Targeted=false;}

if(Hitting.gameObject.tag=="Explosion"){BObTarget=null;Targeted=false;}

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 hotozi · Nov 08, 2012 at 04:48 PM 0
Share

sorry for the mistakes...

avatar image Seth-Bergman · Nov 08, 2012 at 05:06 PM 2
Share

you need to format your code, especially if it is this much. edit your post, select all the code and hit the "010101" button, otherwise no one is likely to bother trying to wade through this

avatar image Seth-Bergman · Nov 08, 2012 at 05:15 PM 1
Share

and what is "Owner"? that is what you are using for your distance check, but what/where is it?

avatar image Seth-Bergman · Nov 08, 2012 at 05:35 PM 1
Share

my guess is that the distance check is working fine, but it is always close enough.. try adding some debug logs:

 function Update(){

 if(ObTarget){                                
   Objectdistance=Vector3.Distance(ObTarget.transform.position,Owner.position);
 Debug.Log("Object Distance is: " + Objectdistance);
 }

 if(BObTarget){

  BObjectdistance=Vector3.Distance(ObTarget.transform.position,Owner.position);

 Debug.Log("B Object Distance is: " + BObjectdistance);
 }

etc...

avatar image hotozi · Nov 09, 2012 at 04:07 AM 0
Share

Owner is the object that the gameobject will be attach to...

and i already use a debug well....a print...and i already checked if the distance is fine and yes it is even if the object is far from the selected distance the variable still get true....so WTF?

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

10 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

Related Questions

Multiple Cars not working 1 Answer

Acces to other object trigger thru other object script 0 Answers

My script doesn work Trigger Problem!! HELP!! 3 Answers

A transform.position to act as a Vector3 1 Answer

Message sender...how to know who send the message 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