Question by
alexay007 · Apr 23, 2017 at 10:00 PM ·
c#javascriptvariable
How to Modify a java Script variable with a c# Script
i want to add 10 seconds in a timer when I kill an enemy. This is the countdown java Script:
var Timer = 60;
var Bonus = 0;
function Start(){
yield WaitForSeconds(Timer + Bonus);
Application.LoadLevel("inicio");
}
and this is the C# enemies Script
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class DamageManager : MonoBehaviour
{
public GameObject[] deadbody;
public AudioClip[] hitsound;
public int hp = 100;
public int Score = 10;
private Vector3 velositydamage;
private float distancedamage;
void Start(){
}
void Update(){
if (hp <= 0) {
Dead (Random.Range (0, deadbody.Length));
}
}
public void ApplyDamage (int damage, Vector3 velosity, float distance)
{
if (hp <= 0) {
return;
}
distancedamage = distance;
hp -= damage;
velositydamage = velosity;
}
public void ApplyDamage (int damage, Vector3 velosity, float distance, int suffix)
{
if (hp <= 0) {
return;
}
distancedamage = distance;
hp -= damage;
velositydamage = velosity;
if (hp <= 0) {
Dead (suffix);
}
}
public void AfterDead (int suffix)
{
int scoreplus = Score;
if(suffix == 2){
scoreplus = Score * 5;
}
ScoreManager score = (ScoreManager)GameObject.FindObjectOfType (typeof(ScoreManager));
if(score){
score.AddScore (scoreplus, distancedamage);
}
}
// ** Important! for Ragdoll replacement
private AS_RagdollReplace ragdollReplace;
public void Dead (int suffix)
{
if (deadbody.Length > 0 && suffix >= 0 && suffix < deadbody.Length) {
// this Object has removed by Dead and replaced with Ragdoll. the ObjectLookAt will null and ActionCamera will stop following and looking.
// so we have to update ObjectLookAt to this Ragdoll replacement. then ActionCamera to continue fucusing on it.
GameObject deadReplace = (GameObject)Instantiate (deadbody [suffix], this.transform.position, this.transform.rotation);
ragdollReplace = deadReplace.GetComponent<AS_RagdollReplace> ();
// copy all of transforms to dead object replaced
CopyTransformsRecurse (this.transform, deadReplace);
// destroy dead object replaced after 5 sec
Destroy (deadReplace, 5);
// destry this game object.
Destroy (this.gameObject,1);
this.gameObject.SetActive(false);
}
AfterDead (suffix);
}
// Copy all transforms to Ragdoll object
public void CopyTransformsRecurse (Transform src, GameObject dst)
{
dst.transform.position = src.position;
dst.transform.rotation = src.rotation;
foreach (Transform child in dst.transform) {
var curSrc = src.Find (child.name);
if (curSrc) {
CopyTransformsRecurse (curSrc, child.gameObject);
}
}
}
}
How can I connect the Scripts
Comment
Answer by WhipJr · Apr 24, 2017 at 01:26 AM
it is not advised to cross languages like this, if it does not cause errors now, it will during compiling into an actual application. i would convert the java file to a c# if i were you.