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 VTpalys · Apr 10, 2014 at 06:01 AM · js-c#

Trying to convert Js to C#

hi folks, im trying to convert this Js: var emptyslot : Transform; var xtemp; var ytemp;

     function OnMouseUp(){
     
         if (Vector3.Distance(transform.position,emptyslot.position)==1)  
         {
             xtemp=transform.position.x;
             ytemp=transform.position.y;
             transform.position.x=emptyslot.position.x;
             transform.position.y=emptyslot.position.y;
             emptyslot.position.x=xtemp;
             emptyslot.position.y=ytemp;
         }
         
     }


I came to this result:

 using UnityEngine;
 using System.Collections;
 
 public class mov : MonoBehaviour {
 
     public Transform vazio;
     private float xtemp;
     private float ytemp;
 
     void  OnMouseUp (){
 
         if (Vector3.Distance(transform.position,vazio.position)==1f)  
         {
             xtemp = transform.position.x;
             ytemp = transform.position.y;
             transform.position = vazio.position;
             vazio.position.x = xtemp;
             vazio.position.y = ytemp;
 
         }
 
     }
 }


BUT this don't work. Can someone help me?

Comment
Add comment · Show 6
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 ivomarel · Apr 10, 2014 at 06:22 AM 1
Share

This don't work? I'm sure that's not the error that Unity gave you. Please be specific on what doesn't work and what the error message is.

For one thing, you can't set the position of 'vazio' like that. Ins$$anonymous$$d use:

 vazio.position = new Vector3(xtemp, ytemp, 0);
avatar image haim96 · Apr 10, 2014 at 06:55 AM 0
Share

where do you get an error and what kind?

avatar image VTpalys · Apr 10, 2014 at 09:37 AM -1
Share

Assets/scripts/mov.cs(17,31): error CS1612: Cannot modify a value type return value of UnityEngine.Transform.position'. Consider storing the value in a temporary variable Assets/scripts/mov.cs(18,31): error CS1612: Cannot modify a value type return value of UnityEngine.Transform.position'. Consider storing the value in a temporary variable

These are the errors that appeared before, Now I made the changes you suggested. It's working! VERY GRATEFUL!

avatar image Berenger VTpalys · Apr 10, 2014 at 09:38 AM 0
Share

Could you tell me who helped you out so I can clean up this thread please ?

avatar image VTpalys VTpalys · Apr 10, 2014 at 04:00 PM 0
Share

ivomarel helped me, very grateful!

avatar image Benproductions1 VTpalys · Apr 10, 2014 at 08:35 PM 0
Share

Please do not post comments as answers.

1 Reply

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

Answer by Mikael-Gyth · Apr 10, 2014 at 09:36 AM

@ivmarel is correct, you are probably getting an error for trying to set the readonly values of position.x and position.y

 using UnityEngine;
         using System.Collections;
 
 
 public class mov : MonoBehaviour {
          
             public Transform vazio;
             private float xtemp;
             private float ytemp;
          
             void  OnMouseUp (){
          
                if (Vector3.Distance(transform.position,vazio.position)==1f)  
                {
                  xtemp = transform.position.x;
                  ytemp = transform.position.y;
                  transform.position = vazio.position;
                  vazio.position = new Vector3(xtemp, ytemp, 0);
          
                }
          
             }
         }

Atleast that is the only thing wrong with the script, but ofcoure there can be other issues that cause it, but that is hard to tell without the actual error message.

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

26 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

js to C# converstion Problem 3 Answers

JS to C# Translation? 2 Answers

how to convert string into numbers in C# 2 Answers

How To Separate Json Parameter Function to get values i need ? 0 Answers

Can you Help me about how to get the variable of Java Script to C# script? 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