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 banana111 · Dec 13, 2014 at 11:30 AM · transformpositioncubexthis

how can i target a nother cube from a script

i made a script where by clicking on a cube/button it moves how do i make it so that when i click it it moves a nother cube not the cube that i clickd pls help here is the script:

 var speed : float = 0.2;
 var timer : float = 0;
 var player = this;
 
 function Update (){
    if(timer >= 1)
 
 //here is the line wherei would like to move a nother cube
 
    {
       this.transform.position.x += this.speed;            
    }
 }
 
 
 
 function OnMouseDown () {
     timer++;
 }
 
 function OnMouseUp () {
     timer--;
 }




i would like i tthat when it says:

this.transform.position.x += this.speed;

it would move a nother cube pls help tnx

Comment
Add comment · Show 4
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 Qasem2014 · Dec 13, 2014 at 11:57 AM 0
Share

add a new variable :

 var anothercube :GameObject;

then your script should be like this :

 anothercube.transform.position.x += this.speed;

anothercube is the cube that you wana move it ! add your cube in editor to the anothercube variable then play ! or you just find it in start() function like this :

 anothercube = GameObject.Find('your cube name');
avatar image banana111 Qasem2014 · Dec 13, 2014 at 12:23 PM 0
Share

wow thank you it works oh my gosh im so greatful thank you this unity furom thing realy pays of thank you again. i was trying to solve this problome for the past day (im a biginer) thank you.

avatar image justin35f Qasem2014 · Dec 15, 2014 at 09:03 PM 0
Share

Please accept @Qasem2014 's answer if it solved your problem. Thanks!

avatar image Qasem2014 Qasem2014 · Dec 21, 2014 at 06:26 AM 0
Share

link text I convert my comment to answer , so you can close the question if your problem solved

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by banana111 · Nov 05, 2018 at 03:37 PM

Yo your such a noob.. omg ... you need to declare the object as a var. public Gameobject something; since it's a public Gameobject you can set the Gamobject variable to be equal to your desired object in the inspector. In your code change the this. to something. something being your new Game Object variable you just created. ALso learn how to code c# my response was in c# who still uses java script wtf noob.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How To Drag any Cube Using Mouse Click and Moved Only 1 Unit?? 2 Answers

does not work check if dead 1 Answer

Help around an approach to a "Virtual Motion Table" in Unity 0 Answers

Instantiated prefab position 5 Answers

Setting Position of Spawned Prefab 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