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 IMTRIGGERHAPPY9 · Oct 09, 2011 at 10:09 PM · movegetmousebutton

if button help?

   var towerGhost : Transform;
 var towerActual : Transform;
 var gridPoint : Vector3;
 
 
 function Update () {
     var hit : RaycastHit;
     var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
     var ghostTower : Transform;
     
       if ( Physics.Raycast( ray, hit, 100 ) ){
         
         if (hit.collider.CompareTag("gridFloor")){
             
             gridPoint = hit.collider.transform.position;
             
             
             if(gridPoint != null){
                 
                 if(Input.GetMouseButtonDown(0)){
                     ghostTower = Instantiate(towerGhost,gridPoint,Quaternion.identity);
                 }
                 if(Input.GetMouseButton(0)){
                     ghostTower.position = gridPoint;
                     }
                 }
                 if(Input.GetMouseButtonUp(0)){
                     Instantiate(towerActual,gridPoint,Quaternion.identity);
                 }
                         
                 
                     }
                 
                 }
             }
         

does anybody know why this wouldn't be working?

both ghost tower and gridpoint have been assigned and are showing up in debug.log i dont get it

Update: ok so i posted my entire script hoping it would make more sense now.

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 syclamoth · Oct 09, 2011 at 10:16 PM 0
Share

gridPoint is a Vector3, no? If ghostTower is a transform, you really don't need the .gameObject.transform bit to refer to itself...

avatar image IMTRIGGERHAPPY9 · Oct 09, 2011 at 10:28 PM 0
Share

i guess i should add that the object i am trying to move has just been instantiated at gridPoint and now it wont track to my current grid point, and i just deleted the gameObject and transform, but still no cigar

2 Replies

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

Answer by syclamoth · Oct 09, 2011 at 10:55 PM

OHHHH!!! I know what your problem is now.

You are defining your variable 'ghostTower' in the wrong scope! You need to put it at the top of your script, where it won't get overwritten every time Update gets called! The way it is a the moment, it'll never get saved between frames. I remember the first part of this question, and I was really racking my brains to work out what was going wrong, but now that I've seen your whole script, it makes sense.

Just make it private so it doesn't show up in the inspector, but put it at the top next to your prefab declarations. Then, you'll be able to reference it beyond the frame when you spawned it!

Comment
Add comment · Show 1 · 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 IMTRIGGERHAPPY9 · Oct 10, 2011 at 03:05 AM 0
Share

Thank you dude! i guess next time i should just post my entire script ha ha i appreciate all the help!

avatar image
0

Answer by MrSplosion · Oct 09, 2011 at 10:17 PM

Try taking the GameObject out.

 if(Input.GetMouseButton(0)){
      ghostTower.transform.position = gridPoint;
 }
Comment
Add comment · Show 3 · 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 IMTRIGGERHAPPY9 · Oct 09, 2011 at 10:19 PM 0
Share

still wont work

avatar image MrSplosion · Oct 09, 2011 at 10:22 PM 0
Share

ok, well like syclamoth said is gridPoint a Vector3?

avatar image IMTRIGGERHAPPY9 · Oct 09, 2011 at 10:31 PM 0
Share

yes, sorry forgot to add that to

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

how to move or fade GUITextures with iTween 2 Answers

How do you make an object go left and right? 1 Answer

Top-Down Camera Trouble 1 Answer

walking around a spheroid planet centered at the origin 1 Answer

Make Explosion Child of Target 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