Search Unity

Need help with a convert C# script.

Discussion in 'Scripting' started by AcidicPaper, Jan 10, 2016.

  1. AcidicPaper

    AcidicPaper

    Joined:
    Feb 11, 2015
    Posts:
    12
    I recently tried my luck with a JavaScript/C# Converter - that is converting the Javascript into a C# script.

    Screen Shot 2016-01-10 at 18.11.34.png

    Heres the converted script. Clearly there are things that I need to perform myself to finish the problematic script though.

    First, I need to know what this error means:

    Screen Shot 2016-01-10 at 18.15.20.png

    I've tried making adjustments myself but to no avail (I apologise for my tremendous newness to this).

    Secondly, I have changed the MYCLASSNAME to the Game asset that I want the script to apply to = the Player asset (a ball that will be confined to a predetermined area). But I still dont think it's working.

    If anyone can give me any advice on how to remedy this id be very grateful. Many Thanks!
     
  2. hckhenrique

    hckhenrique

    Joined:
    Dec 15, 2015
    Posts:
    5
    The class name needs to be the same name of the file.. also many other erros, should be something like this:

    using UnityEngine;
    using System.Collections;

    public class CircleScriptnew : MonoBehaviour {

    private float mouseX;
    private float mouseY;

    void Update(){
    mouseX = Input.mousePosition.x;
    mouseY = Input.mousePosition.y;

    Vector3 worldPos = Camera.main.ScreenToWorldPoint( new Vector3(mouseX, mouseY, 10));

    if(worldPos.y > transform.position.y){
    transform.Translate(Vector3.up * Time.deltaTime) ;
    }else if(worldPos.y < transform.position.y){
    transform.Translate( (new Vector3(0,-1,0)) * Time.deltaTime);
    }

    if(worldPos.x > transform.position.x){
    transform.Translate(Vector3.right * Time.deltaTime);
    }else if( worldPos.x < transform.position.x){
    transform.Translate( (new Vector3(-1,0,0)) * Time.deltaTime);
    }

    }

    }
     
  3. AcidicPaper

    AcidicPaper

    Joined:
    Feb 11, 2015
    Posts:
    12
    How did I not see that?! You legend. Thank you :)
     
  4. RuinsOfFeyrin

    RuinsOfFeyrin

    Joined:
    Feb 22, 2014
    Posts:
    785
    @hckhenrique
    You have done the original poster a HUGE dis-service by basically fixing his problems for him. He has learned... nothing... which is no good since he obviously already knows nothing what so ever.

    Perhaps next time an explanation of what you changed and why, because im am 99% positive the op simply copy and pasted your code, which he got somewhere in javascript and copy and pasted in to a converter....

    "Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime."
     
  5. hckhenrique

    hckhenrique

    Joined:
    Dec 15, 2015
    Posts:
    5
    You are totally right.. so sorry about that.. A

    ctually I posted a question. Im having a problem with mouse position ( http://forum.unity3d.com/threads/mouse-in-3d-world.378792/ ). And since I am waiting for an answer I tried to find posts where I could help.
     
  6. RuinsOfFeyrin

    RuinsOfFeyrin

    Joined:
    Feb 22, 2014
    Posts:
    785
    @hckhenrique

    Its all good. Its not your fault, i was more disappointed that the op either did not attempt to figure this out for themselves, or has absolutely no grasp of c# (and probably programming) and is simply copy and pasting scripts and then asking why it doesn't work instead of taking the time to attempt to learn a little about the language they are attempting to "use".
     
  7. AcidicPaper

    AcidicPaper

    Joined:
    Feb 11, 2015
    Posts:
    12
    Thank you very much for your, shall I say, less than kind descriptive of how you think I had this issue resolved for me.

    Not that it is any of your business of how much I know about C#, but I had already spent a considerable amount of time trying to figure out the solution behind why script was failing. I had learnt the Javascript from a YouTube tutorial which had become outdated, and so wanted to convert it to C# for ease with the tutorial I am taking for that specific language code.

    You may think I am cutting a corner by asking someone who knows more about code than I do to simply do it for me, but still it really isn't your business to be blaming me for this are you? You were at my position of learning once before, so I forgive you for your abrasiveness.