- Home /
Need hep with pooling(call Cs in Js)
Oke so im using Prefactory as my pooling scripts.Prefactory blog
The first problem i had to get over was,how to call to the C# from a Js script and despawning an object. i got it working,though there i now some un needed code in the Js. (im a total rookie in coding)
Note: its about despawning bullet prefab
private var nonsense : float = 0.0;
var thisdoesnothign : float = 0;
var DespawnDelay = 0.0;
function Awake() {
}
function Start(){
}
function Update(){
thisdoesnothign += Time.deltaTime;
if (thisdoesnothign >= DespawnDelay){
thisdoesnothign = 0;
if(nonsense > 0){
Debug.Log(“nonsense”);
} else{
PoolManager.Despawn(gameObject);}
}
}
the codes private var nonsense : float = 0.0; and var thisdoesnothign : float = 0; do absolutly nothing,but thats not my biggest concern now.
The problem that im now facing is this code. I need to shoot the bullet prefab from my BSawnPoint(spawnpoint from where to shoot the bullet,the spawn point is invisible and placed in the barrel of the gun.)
public var bulletPrefab : Transform;
public var bulletSpeed : float = 6000;
var ShotDelay = 5.0;
var timer : float = 0;
var rotateJoystick : Joystick;
function Update(){
if (rotateJoystick.IsFingerDown()){
timer += Time.deltaTime;
if (timer >= ShotDelay){
timer = 0;
if(!bulletPrefab || !bulletSpeed){
Debug.Log(“[shoot] ‘bulletPrefab’ or ‘bulletSpeed’ is undefined”);
} else{
var bulletCreate = Instantiate(bulletPrefab, GameObject.Find(“BSpawnPoint”).transform.position, Quaternion.identity);
bulletCreate.rigidbody.AddForce(transform.forward * bulletSpeed);
//PoolManager.Spawn(“Bullet”).rigidbody.AddForce(transform.forward * bulletSpeed); <—Works but does not shoot from gameobject"BSpawnPoint".instead it shoots from x.0 y.0 z.0.
}
}
}
}
function Spawn()<--Function that i used to just spawn and debug/see if the code worked at all.
{
PoolManager.Spawn("Bullet");
}
Your answer
Follow this Question
Related Questions
How to add impact sparks / blood effects to 2D shooter? 2 Answers
Showing a dynamic amount of bullets in a Belt/Magazine/Cylinder 0 Answers
default reference missing in prefabs 0 Answers
GameObject Pool heaving difficulties getting a pool at all trying to find different aproach 1 Answer
The code is giving me errors 1 Answer