- Home /
Question by
ReflectedMirror · Aug 21, 2014 at 07:45 PM ·
transformobject
Error: Assets/Scripts/AxeAttack.js(41,35): BCE0019: 'transform' is not a member of 'Object'
I get this error: Assets/Scripts/AxeAttack.js(41,35): BCE0019: 'transform' is not a member of 'Object'
in this script:
#pragma strict
private var isAttacking : boolean = true;
private var attackCoolDown = 0.0;
var damage = 50;
var range = 5;
private var mainCamera;
function Start () {
isAttacking = false;
mainCamera = GameObject.FindWithTag("MainCamera");
}
function Update () {
if(isAttacking)
{
attackCoolDown += Time.deltaTime;
if(attackCoolDown >= 2)
{
isAttacking = false;
attackCoolDown = 0.0;
}
}
if(Input.GetMouseButtonDown(0) && isAttacking == false)
{
Attack();
}
if(isAttacking == false)
{
this.gameObject.animation["idle_cube"].wrapMode = WrapMode.Loop;
this.gameObject.animation.CrossFade("idle_cube");
}
}
function Attack ()
{
this.gameObject.animation.CrossFade("attack_cube");
isAttacking = true;
attackCoolDown = 1;
var direction = transform.TransformDirection(Vector3.forward);
var hit : RaycastHit;
Debug.DrawLine(mainCamera.transform.position,direction*range,Color.red);
if (Physics.Raycast (mainCamera.transform.position, direction, hit, range));
{
if(hit.transform.tag == "Enemy")
{
hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
}
}
}
I am pretty new to UnityScript, sorry x)
Comment
Best Answer
Answer by rutter · Aug 21, 2014 at 07:45 PM
If you don't specify a type for a variable, UnityScript will try to guess a type using whatever information you provided in the variable declaration.
In this case, no such information is available, so it's guessing the most general type: "Object"
var someVariable; //type "Object"
var someVariable1 = 5; //type "int"
var someVariable2 = "foo"; //type "String"
You can specify a type to be more specific:
var mainCamera : GameObject;
Your answer
Follow this Question
Related Questions
Huge objects dissapear 1 Answer
moving random objects to random positions 1 Answer
How to make a object face another object 1 Answer
Move Object to location of Trigger? 1 Answer