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 kerzker · Jan 18, 2013 at 03:49 PM · c#javascripttranslateconvert

Can someone help me translate this to c#?

We really really need this done within the next two or three days. We'll credit whoever does it first in our game. Thanks so much!

 #pragma strict
 var spawner : Transform;
 var projectile : Transform;
 var bulletCount = 0;
 var damp = .3;
 static var fastFire = false;
 private var nextFire = 0.0;
 var fireRate = 0.1;
 
 function Start () {
 bulletCount = 0;
 }
 
 function Update () {
 var playerplane = new Plane(Vector3.up, transform.position);
 var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
 var target = 0.0;
  if(playerplane.Raycast (ray, target)){
     var targetpoint = ray.GetPoint(target);
     var targetRotation = Quaternion.LookRotation(targetpoint - transform.position);
     //transform.rotation = targetRotation;
     transform.rotation = Quaternion.Slerp(transform.rotation,targetRotation, Time.deltaTime * damp);
     }
 
 // && bulletCount <7
 
 if(Input.GetMouseButtonDown(0) && fastFire == false)
  {
   bulletCount += 1;
   var bullet = Instantiate(projectile,spawner.position,Quaternion.identity);
    bullet.rigidbody.AddForce(transform.forward * 1000);
    audio.Play();
  }    
  if(Input.GetMouseButton(0) && fastFire && Time.time > nextFire)
  {
   nextFire = Time.time + fireRate;
   bulletCount += 1;
   var bullet2 = Instantiate(projectile,spawner.position,Quaternion.identity);
    bullet2.rigidbody.AddForce(transform.forward * 1000);
    audio.Play();
 
    
  }
 // bullet.rigidbody.AddForce(transform.forward * 1000)x;
     
     
     
 }


Thank you so much :)

Comment
Add comment · Show 2
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 $$anonymous$$ · Jan 18, 2013 at 04:07 PM 0
Share

If you're writing the game in C#, why can't you translate it? Not that there's anything special in this, approx. 60 seconds of work. Just give proper types for the members in the declaration section, like Transform spawner;

function Update() --> void Update().

In UnityScript the members are public by default, but in C# they are private by default, so if you want them public (visible in the inspector), make them public: public Transform spawner; but you should already know these if you need the stuff in C#.

avatar image kerzker · Jan 18, 2013 at 05:26 PM 0
Share

alt text

And that is all :)

156305_427714737298653_567247950_n.jpg (61.3 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by dorpeleg · Jan 18, 2013 at 04:13 PM

I had some time so I made it for you:

 public Transform spawner;
 public Transform projectile;
 public int bulletCount = 0;
 public float damp = 0.3f;
 Transform static bool fastFire = false;
 private float nextFire = 0.0f;
 public float fireRate = 0.1f;
 
 private Ray ray;
 public float target;
 public GameObject bullet,bullet2;
 public Vector3 targetpoint;
 public Quaternion targetRotation;
 public bool fastFire = false;
 
 void Start () {
 bulletCount = 0;
 }
 
 void Update () {
 Plane playerplane = new Plane(Vector3.up, transform.position);
 ray = Camera.main.ScreenPointToRay (Input.mousePosition);
 target = 0.0f;
  if(playerplane.Raycast (ray, out target)){
     targetpoint = ray.GetPoint(target);
     targetRotation = Quaternion.LookRotation(targetpoint - transform.position);
     //transform.rotation = targetRotation;
     transform.rotation = Quaternion.Slerp(transform.rotation,targetRotation, Time.deltaTime * damp);
     }
 
 // && bulletCount <7
 
 if(Input.GetMouseButtonDown(0) && fastFire == false)
  {
   bulletCount += 1;
   bullet = Instantiate(projectile,spawner.position,Quaternion.identity);
   bullet.rigidbody.AddForce(transform.forward * 1000);
   audio.Play();
  }  
  if(Input.GetMouseButton(0) && fastFire && Time.time > nextFire)
  {
   nextFire = Time.time + fireRate;
   bulletCount += 1;
   bullet2 = Instantiate(projectile,spawner.position,Quaternion.identity);
   bullet2.rigidbody.AddForce(transform.forward * 1000);
   audio.Play();
 
 
  }
 // bullet.rigidbody.AddForce(transform.forward * 1000)x;

You can play around with the public/private however you want. I didn't test this so if it gives you errors let me know and i'll try to fix it.

Comment
Add comment · Show 9 · 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 kerzker · Jan 18, 2013 at 04:48 PM 0
Share

Hey man, thanks so much. It generates a few errors, though.

Have a look, I've just uploaded the image as another answer to my question.

avatar image dorpeleg · Jan 18, 2013 at 05:13 PM 0
Share

I don't see any image or anything. you can just copy paste the log here as a comment and I'll look at it.

avatar image kerzker · Jan 18, 2013 at 05:25 PM 0
Share

Good plan, done and done :)

Assets/LookAtC.cs(47,3): error CS0266: Cannot implicitly convert type UnityEngine.Object' to UnityEngine.GameObject'. An explicit conversion exists (are you missing a cast?)

Assets/LookAtC.cs(43,32): error CS0103: The name fastFire' does not exist in the current context Assets/LookAtC.cs(39,3): error CS0266: Cannot implicitly convert type UnityEngine.Object' to UnityEngine.GameObject'. An explicit conversion exists (are you missing a cast?) Assets/LookAtC.cs(36,35): error CS0103: The name fastFire' does not exist in the current context

Assets/LookAtC.cs(31,37): error CS1503: Argument #2' cannot convert UnityEngine.Vector3' expression to type UnityEngine.Quaternion' Assets/LookAtC.cs(27,5): error CS0103: The name playerplane' does not exist in the current context

Assets/LookAtC.cs(24,1): error CS0103: The name playerplane' does not exist in the current context Assets/LookAtC.cs(31,37): error CS1502: The best overloaded method match for UnityEngine.Quaternion.Slerp(UnityEngine.Quaternion, UnityEngine.Quaternion, float)' has some invalid arguments

Assets/LookAtC.cs(29,5): error CS0029: Cannot implicitly convert type UnityEngine.Quaternion' to UnityEngine.Vector3'

avatar image dorpeleg · Jan 18, 2013 at 05:48 PM 0
Share

Ok, I think I fixed it. Give it a try and see if it give more errors.(I edited my original post)

avatar image kerzker · Jan 18, 2013 at 05:58 PM 0
Share

That took care of most of them, but there are two remaining

Assets/LookAtC.cs(25,16): error CS1502: The best overloaded method match for UnityEngine.Plane.Raycast(UnityEngine.Ray, out float)' has some invalid arguments Assets/LookAtC.cs(25,16): error CS1620: Argument #2' is missing `out' modifier

Thanks so much man :P

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

Multiple Cars not working 1 Answer

How to make this line work in C#? 1 Answer

java to C# conversion 1 Answer

Help with conversion from javascript to c# 3 Answers

this script in Javascript?? 0 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