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 smirlianos · Oct 07, 2012 at 06:06 PM · javascripttransform.positionmouseclick

Transform.position problem Please help?

I have the following script. When the user clicks a button, I want the camera to move to an other position, but it doesn't work. Any help?

 var cameraobj : GameObject;
 var target : GameObject;
 
 function OnMouseUp() 
 {
     cameraobj.transform.position = target.position;
 }
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Eric5h5 · Oct 07, 2012 at 06:13 PM

If you want input in general, use the Input class in Update. OnMouseUp is a callback for clicking on a particular object.

Comment
Add comment · Show 8 · 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 smirlianos · Oct 08, 2012 at 04:03 PM 0
Share

But i want the user to press a button to move the camera, not just click anywhere... :(

avatar image MibZ · Oct 08, 2012 at 04:17 PM 0
Share

Then add if statements so it only works when the user presses the button you want.

avatar image smirlianos · Oct 08, 2012 at 04:31 PM 0
Share

I changed the script to this

var cameraobj : Camera; var target : GameObject; var pressed : boolean;

function Update() { if(Input.Get$$anonymous$$ouseButtonDown(1) && pressed == true) { cameraobj.transform.position = target.position; } }

function On$$anonymous$$ouseUp() { pressed = true; }

but it continues have an error:

NullReferenceException: Object reference not set to an instance of an object Camera $$anonymous$$ove.Update () (at Assets/Camera $$anonymous$$ove.js:9)

avatar image MibZ · Oct 08, 2012 at 04:35 PM 0
Share

When you double click the NullReferenceException in the console, what line does it highlight in your code?

Also - you don't need to add the pressed variable, you only need Unity's included $$anonymous$$ouseDown/$$anonymous$$ouseUp check functions.

if (Input.Get$$anonymous$$ouseButtonDown(1)) cameraobj.transform.position = target.position;

avatar image smirlianos · Oct 08, 2012 at 04:44 PM 0
Share

it is at line 9. if i put the if (Input.Get$$anonymous$$ouseButtonDown(1)) cameraobj.transform.position = target.position;

when i click anywhere, the camera, but again it has this error

NullReferenceException: Object reference not set to an instance of an object Camera $$anonymous$$ove.Update () (at Assets/Camera $$anonymous$$ove.js:9)

(the script is attached to the box/button, should i change this?

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

11 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

Related Questions

How can I detect a right-click on my UI button? 1 Answer

How would I move an Object after collision? 1 Answer

How To Detect MouseClick Using Raycast Java Script 0 Answers

Script error: respawn upon collission 2 Answers

Move different objects from point A to B with objects having different time to move b/w these points. 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