- Home /
Bomberman in 1st person
Hi I want to make a bomberman game in 3d.So that I need to build a coding it which I decided to go with javascript.The character of the bomb is that it should destroy bricks and players inside its affected area but it should not affect the concrete walls.I have a coding here which gives the following error
Assets/Standard Assets/Scripts/General Scripts/NewBehaviourScript.js(31,61): BCE0005: Unknown identifier: 'Player'.
The coding is
#pragma strict
var power : float = 100;
var damage : int = 1;
var radius : float = 3;
var bombFuseLength : float = 3;
private var startTime : float;
private var actualTime : float;
function Start ()
{
startTime = Time.time;
}
function Update ()
{
actualTime = Time.time - startTime;
if (actualTime > bombFuseLength)
{
Explode();
}
}
function Explode ()
{
GameObject.Find("First Person Controller").GetComponent(Player).bombs +=1;
var colliders : Collider[] = Physics.OverlapSphere (transform.position, radius);
Debug.Log("Count of colliders = "+colliders.Length);
for (var collider : Collider in colliders)
{
if (collider.tag == "brick" || collider.tag == "player")
{
Debug.Log("Found brick or a player");
var hit : RaycastHit;
if (Physics.Linecast(transform.position, collider.transform.position, hit))
{
if (hit.collider == collider)
{
Debug.Log("No obstructions");
if (hit.rigidbody)
hit.rigidbody.AddExplosionForce(power, transform.position, radius, 3.0);
Destroy (gameObject);
}
}
}
}
}
First of all I've got this coding from a friend of mine and I do know only the basics about this coding.So please let me know what to do to clear error and feel free to edit this to build in a correct format
Answer by fafase · Jan 22, 2014 at 07:20 PM
The line below in the Explode method:
GameObject.Find("First Person Controller").GetComponent(Player).bombs +=1;
it requires the player to have a script of type player. Your friend gave you this script but he was using this Player script you do not have in your project.
So you need to ask him what was this Player script about and implement it.
Your answer
Follow this Question
Related Questions
get a height of a gameobject 1 Answer
Movement script, moving up when moving positively in z axis 1 Answer
How to create a game object through a function 2 Answers
invalid cast exception, array of particle systems 0 Answers
Temperature Script? 3 Answers