Java script into c#? please help me im stuck.... (solved)

Ok so i have this javascript and iam trying to transfer it into c# but im stuck could someone please help me?
this is the java code:

#pragma strict

var treeHealth : int = 5;

var logs : Transform;
var tree : GameObject;

var speed : int = 8;

function Start()
{
tree = this.gameObject;
GetComponent.().isKinematic = true;
}

function Update()
{
if(treeHealth <= 0)
{
GetComponent.().isKinematic = false;
GetComponent.().AddForce(transform.forward * speed);
DestroyTree();
}
}

function DestroyTree()
{
yield WaitForSeconds(7);
Destroy(tree);

var position : Vector3 = Vector3(Random.Range(-1.0, 1.0), 0, Random.Range(-1.0, 1.0));
Instantiate(logs, tree.transform.position + Vector3(0,0,0) + position, Quaternion.identity);
Instantiate(logs, tree.transform.position + Vector3(2,2,0) + position, Quaternion.identity);
Instantiate(logs, tree.transform.position + Vector3(5,5,0) + position, Quaternion.identity);

}

and this is my c# script so far the problem is that when i transfer the last bit were you have the function destroy tree all the transforms don’t work… :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class treeController : MonoBehaviour {

public float treeHealth = 5.0f;
public float logs = Transform;
GameObject tree;
public float speed = 8.0f;
Rigidbody rb;

// Use this for initialization
void Start () {
rb = GetComponent();
rb.isKinematic = true;
tree = this.gameObject;
}

// Update is called once per frame
void Update () {
if (treeHealth <= 0)
{
rb.isKinematic = false;
rb.AddForce(transform.forward * speed);
DestroyTree();
}

}

Hi HetIsKane, please use Code Tags when posting code: Using code tags properly

When you destroy an object you also destroy everything else associated with that object, including its transform. Either call Destroy after instantiating your logs or save the transform’s position in a variable and use that instead:

Vector3 treePos = tree.transform.position;
Destroy(tree);
...
Instantiate(logs, treePos + Vector3(0, 0, 0) + position, Quaternion.identity);

There’s an official conversion script in the works, you can get hold of it here .

Thank you :slight_smile: