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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by ineteye · Oct 11, 2012 at 08:33 PM · c#

Need help converting js to C

Hi!

original js script:

 #pragma strict
 #pragma implicit
 #pragma downcast
 
 static var destroyed:int=0;
 
 var score10:Material;
 var score30:Material;
 var score50:Material;
 var score100:Material;
 var score150:Material;
 var score200:Material;
 var score250:Material;
 var score3000:Material;
 var scoreParticle:GameObject;
 
 
 var crackSound:AudioClip;
 
 private var color:Color;
 private var object:Vector3;
 
 public var container :GameObject;
 
 
 function Update()
 {
     if (Input.GetButtonDown("Fire1")) 
     {
            var ray = GetComponent.<Camera>().ScreenPointToRay (Input.mousePosition); //ray from camera to mouse position, we use this for clicking on balls
            var hit : RaycastHit; 
            if ( Physics.Raycast (ray, hit, 30.0) ) //if we hit something
            { 
                if(hit.rigidbody)
                { //and it is rigidbody
                   object=hit.collider.transform.position;  // hitted object's position
                   color=hit.collider.renderer.material.color; //hitted object's color
                 hit.collider.gameObject.GetComponent.<chack>().Start(); //enable hitted object's chack script,
                 audio.volume=0.7;
                 audio.PlayOneShot(crackSound); //play crackSound
                 if(destroyed <= 0 && (int.Parse(container.GetComponent(instantiate).score) >= 10))
                 { //if we clicked and don't destroyed any balls
                     var minusScore=Instantiate(scoreParticle, object - Vector3(0,0,0.3), Quaternion.identity) as GameObject; //instantiate scoreParticle
                     minusScore.renderer.material=score10; //give material to scoreParticle
                     minusScore.renderer.material.color = color;//give ball's color to scoreParticle
                     //scoreText.text=""+(int.Parse(scoreText.text) - 10); //minus 10 to score text
                     container.GetComponent(instantiate).score=""+(int.Parse(container.GetComponent(instantiate).score) - 30); //minus 10 to score text
                 }
             }
         }         
     }
 }
 
 
 
 
 function scoresCalculation(){
 yield WaitForSeconds (0.2);
 if(destroyed == 3){//if we destroyed 3 ball
 var score1=Instantiate(scoreParticle, object - Vector3(0,0,0.3), Quaternion.identity) as GameObject; //instantiate scoreParticle
 score1.renderer.material=score30; //give material to scoreParticle
 score1.renderer.material.color = color;//give ball's color to scoreParticle
 //scoreText.text=""+(int.Parse(scoreText.text)+30); //plus 30 to score text 
 container.GetComponent(instantiate).score=""+(int.Parse(container.GetComponent(instantiate).score)+30); //plus 30 to score text 
 }
 }





Converted to C# ... fixed what i can:

 using UnityEngine;

 using System.Collections;

 

 public class clickdetecting : MonoBehaviour 

 {

 

 

 

 public static int destroyed=0;

 

 Material score10;

 Material score30;

 Material score50;

 Material score100;

 Material score150;

 Material score200;

 Material score250;

 Material score3000;

 GameObject scoreParticle;

 

 

 //GUIText scoreText;

 AudioClip crackSound;

 

 private Color color;

 private Vector3 obj;

 

 public GameObject container;

 

 

 void  Update (){

     if (Input.GetButtonDown("Fire1")) 

     {

            //var ray= GetComponent.<Camera>().ScreenPointToRay (Input.mousePosition); //ray from camera to mouse position, we use this for clicking on balls

         //var ray= GetComponent(Camera).ScreenPointToRay (Input.mousePosition); //ray from camera to mouse position, we use this for clicking on balls

         Ray ray = camera.ScreenPointToRay(Input.mousePosition);

            RaycastHit hit = new RaycastHit(); 

            if ( Physics.Raycast (ray,out hit, 30.0f) ) //if we hit something

            { 

                if(hit.rigidbody)

                { //and it is rigidbody

                   obj=hit.collider.transform.position;  // hitted object's position

                   color=hit.collider.renderer.material.color; //hitted object's color

                 //hit.collider.gameObject.GetComponent(chack).Start();//enable hitted object's chack script,

                 hit.collider.gameObject.GetComponent<chack>().Start(); //enable hitted object's chack script,

                 audio.volume=0.7f;

                 audio.PlayOneShot(crackSound); //play crackSound

                 if(destroyed <= 0 && (int.Parse(container.GetComponent<instantiate>().score) >= 10))

                 { //if we clicked and don't destroyed any balls

                     //

                     var minusScore=Instantiate(scoreParticle, obj - Vector3(0,0,0.3f), Quaternion.identity) as GameObject; //instantiate scoreParticle

                     //error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected

                     //error CS1502: The best overloaded method match for `UnityEngine.Object.Instantiate(UnityEngine.Object, UnityEngine.Vector3, UnityEngine.Quaternion)' has some invalid arguments

                     //error CS1503: Argument `#2' cannot convert `object' expression to type `UnityEngine.Vector3'

                     //

                     minusScore.renderer.material=score10; //give material to scoreParticle

                     minusScore.renderer.material.color = color;//give ball's color to scoreParticle

                     //scoreText.text=""+(int.Parse(scoreText.text) - 10); //minus 10 to score text

                     container.GetComponent<instantiate>().score=""+(int.Parse(container.GetComponent<instantiate>().score) - 30); //minus 10 to score text

                 }

             }

         }         

     }

 }

 

 public void scoresCalculation ()

 {

     //yield WaitForSeconds (0.2f);

     //yield return new WaitForSeconds(0.2f);

 // Should i change for yield void to IEnumerator??

     if(destroyed == 3)

     {//if we destroyed 3 ball

         GameObject core1=Instantiate(scoreParticle, obj - Vector3(0,0,0.3f), Quaternion.identity); //instantiate scoreParticle

         score1.renderer.material=score30; //give material to scoreParticle

         score1.renderer.material.color = color;//give ball's color to scoreParticle

         //scoreText.text=""+(int.Parse(scoreText.text)+30); //plus 30 to score text 

         container.GetComponent<instantiate>().score=""+(int.Parse(container.GetComponent<instantiate>().score)+30); //plus 30 to score text 

     }

 }

 

 }
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

0 Replies

· Add your reply
  • Sort: 

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

10 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

Related Questions

Enemy AI script causing Unity to crash (Javascript to C#) 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Need help converting js to C# -- yield return WaitForSeconds 3 Answers

Can this be converted to C#? 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