why my c# Script dont work

when i play and i kill a ennmy he give me a reward like Repair my Ammo so i convert this script to c# in JS script work fine.

so When i clone in hierarchy in prefabe of Repari they must bee targert Player but there is not :S

but in js Script when prefab Repair is in hierarchy the Target have player Prefab :S

This piuc is from C# Script

This on is from JS Scrip[t

and i will put the botth script

using UnityEngine;
using System.Collections;

public class Droppable : MonoBehaviour 
{

	//This script handles the droppables. These are the objects that are picked up by the player and give him either ammo or health.
	
	public Transform Target; //The droppable's target. The object this droppable will be picked up by
	public float SpinSpeed= 90; //The spinning speed of the object. It rotates around the up axis
	public float PickupRange= 1; //The range from which the droppable is attracted by the target, and then picked up
	public float RemoveAfter= 12; //How long to wait before removing this object
	
	public int GunAmmo= 100; //How much gun ammo is added to the player
	public int RocketAmmo= 10; //How much rocket ammo is added to the player
	public int Repair= 20; //How much health is added to the player
	
	public Transform PickupEffect; //The effect displayed when the droppable is picked up
	
	private float TimeSinceCreated= 0; //How long has passed since this object was created

	private Vector3 temp;

	//public void Start()
	//{
	//	temp = transform.position;
	//}
	public void Update() 
	{
		temp = transform.position;

		//Rotate the object around the UP axis at a speed set by SpinSpeed
		transform.Rotate(Vector3.up, SpinSpeed * Time.deltaTime, Space.World);
		
		if ( Target ) //IF the target object exists, do the following
		{
			if ( Vector3.Distance(transform.position, Target.position) < 0.3f ) //If the target is close enough to the object, pick it up
			{
				if ( PickupEffect )    Instantiate(PickupEffect, transform.position, transform.rotation);
				
				//Add to the player's ammo or health
				Target.GetComponent<PlayerControls>().GunAmmo += GunAmmo; //Add gun ammo
				Target.GetComponent<PlayerControls>().RocketAmmo += RocketAmmo; //Add Rocket ammo
				Target.GetComponent<PlayerControls>().Health += Repair; //Increase Health
				
				//Limit the health value to it's maximum
				if ( Target.GetComponent<PlayerControls>().Health > Target.GetComponent<PlayerControls>().MaxHealth )
				{
					Target.GetComponent<PlayerControls>().Health = Target.GetComponent<PlayerControls>().MaxHealth;
				}
				
				Destroy(gameObject); //remove the object
			}

			else if ( Vector3.Distance(transform.position, Target.position) < PickupRange ) //If the object is within pickup range , start pulling it towards the target
			{

				temp.x -= (transform.position.x - Target.position.x) * 0.3f;
				temp.z -= (transform.position.z - Target.position.z) * 0.3f;
			}
		}
		
		TimeSinceCreated += Time.deltaTime; //Keep track of the time that has passed since this object was created
		
		//If the time that passed since creation is larger than RemoveAfter value, start moving the object down, and then remove it
		if ( TimeSinceCreated > RemoveAfter - 1 )
		{
			transform.Translate(Vector3.up * Time.deltaTime * -1, Space.World); //Move the object down
		}
		else if ( TimeSinceCreated > RemoveAfter )
		{
			Destroy(gameObject); //remove the object
		}
	}
}
//This script handles the droppables. These are the objects that are picked up by the player and give him either ammo or health.

var Target:Transform; //The droppable's target. The object this droppable will be picked up by
var SpinSpeed:float = 90; //The spinning speed of the object. It rotates around the up axis 
var PickupRange:float = 1; //The range from which the droppable is attracted by the target, and then picked up
var RemoveAfter:float = 12; //How long to wait before removing this object

var GunAmmo:int = 100; //How much gun ammo is added to the player
var RocketAmmo:int = 10; //How much rocket ammo is added to the player
var Repair:int = 20; //How much health is added to the player

var PickupEffect:Transform; //The effect displayed when the droppable is picked up

private var TimeSinceCreated:float = 0; //How long has passed since this object was created

function Update() 
{
	//Rotate the object around the UP axis at a speed set by SpinSpeed
	transform.Rotate(Vector3.up, SpinSpeed * Time.deltaTime, Space.World);
	
	if ( Target ) //IF the target object exists, do the following
	{
		if ( Vector3.Distance(transform.position, Target.position) < 0.3 ) //If the target is close enough to the object, pick it up
		{
			if ( PickupEffect )    Instantiate(PickupEffect, transform.position, transform.rotation); //Create a nice pickup effect
			
			//Add to the player's ammo or health
			Target.GetComponent("PlayerControls").GunAmmo += GunAmmo; //Add gun ammo
			Target.GetComponent("PlayerControls").RocketAmmo += RocketAmmo; //Add Rocket ammo
			Target.GetComponent("PlayerControls").Health += Repair; //Increase Health
			
			//Limit the health value to it's maximum
			if ( Target.GetComponent("PlayerControls").Health > Target.GetComponent("PlayerControls").MaxHealth )
			{
				Target.GetComponent("PlayerControls").Health = Target.GetComponent("PlayerControls").MaxHealth;
			}
			
			Destroy(gameObject); //remove the object
		}
		else if ( Vector3.Distance(transform.position, Target.position) < PickupRange ) //If the object is within pickup range , start pulling it towards the target
		{
			transform.position.x -= (transform.position.x - Target.position.x) * 0.3;
			transform.position.z -= (transform.position.z - Target.position.z) * 0.3;
		}
	}
	
	TimeSinceCreated += Time.deltaTime; //Keep track of the time that has passed since this object was created
	
	//If the time that passed since creation is larger than RemoveAfter value, start moving the object down, and then remove it
	if ( TimeSinceCreated > RemoveAfter - 1 )
	{
		transform.Translate(Vector3.up * Time.deltaTime * -1, Space.World); //Move the object down
	}
	else if ( TimeSinceCreated > RemoveAfter )
	{
		Destroy(gameObject); //remove the object
	}
}

What is wrong with c# Script tahnkoy for anyy helping

In your C# I would set the Transform Target to the player.

So I’d put "Target = gameObject.Find = “Player”. When the script loads, it should automatically set player to the target transform.

Hopefully that helps. :slight_smile:

tnx :slight_smile: that work