Convert and merge java to c#?
Is there any one can convert my java file to c#. and if you can then please merge my both file in single. because i cant. In first file I have music game object to keep audio scene by scene. In second file i have slider to control volume of this audio from. So any one can This code for game music object in java.
#pragma strict
var musicprefab : Transform;
function Start () {
if(!GameObject.FindGameObjectWithTag("MM")){
var mManager = Instantiate (musicprefab,transform.position, Quaternion.identity);
mManager.name = musicprefab.name;
DontDestroyOnLoad (mManager);
}
}
function Update () {
}
And this code for slider in c#
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class gamemusicslider : MonoBehaviour {
public Slider GameMusicSlider;
public Transform musicprefab;
void Awake(){
DontDestroyOnLoad (this.gameObject);
}
// Use this for initialization
void Start () {
GameMusicSlider = GameObject.Find("GameMusicSlider").GetComponent<Slider>();
GetComponent<AudioSource> ().volume = PlayerPrefs.GetFloat ("CurVol1");
if(GameMusicSlider){
GameMusicSlider.value = GetComponent<AudioSource> ().volume;
PlayerPrefs.Save ();
}
}
// Update is called once per frame
void Update () {
// AudioListener.volume = PlayerPrefs.GetFloat ("CurVol");
slidervolumecontrol1(GameMusicSlider.value);
}
public void slidervolumecontrol1(float volumecontrol1){
GetComponent<AudioSource> ().volume = volumecontrol1;
PlayerPrefs.SetFloat("CurVol1",GetComponent<AudioSource> ().volume);
PlayerPrefs.Save ();
//audio = GetComponent<AudioSource> ().volume;
// audio.volume = volumecontrol1;
}
}
I think you can do this yourself. The JS script is nice and basic so all you are looking at is the difference in the syntax with creating a variable.
var myVarName : Type; //JS
vs
Type myVarName; //C#
where Type is an int or a Vector3 or a Transform etc.
Lose the #pragma
, C# doesnt need it.
Your answer
![](https://koobas.hobune.stream/wayback/20220612075752im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how to use AndroidJavaProxy for Java generics callback 1 Answer
change my code from java to c# 1 Answer
how to create a matrix in C#? 1 Answer
convert js script into C# 1 Answer
How can i have var in c# 0 Answers