- Home /
The nested type `TransformDirection' does not exist in the type `UnityEngine.Transform'
I get this error with the following script
using UnityEngine;
using System.Collections;
public class Projectile : MonoBehaviour {
public GameObject projectile;
public GameObject proxy;
float firerate=0.5F;
float nextfire;
float speed=5f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetButton ("Fire1")&&Time.time>nextfire){
nextfire=Time.time+firerate;
GameObject clone= Instantiate(projectile, proxy.transform.position, proxy.transform.rotation) as GameObject;
clone.rigidbody.velocity= new Transform.TransformDirection(Vector3(0,0, 2));
Physics.IgnoreCollision(clone.collider,transform.root.collider);
}
}
}
specificaly this line:
clone.rigidbody.velocity= new Transform.TransformDirection(Vector3(0,0, 2));
Comment
Answer by robertbu · Apr 25, 2014 at 05:30 PM
You are using big 'T' Transform which refers to the class. You want little 't' transform which refers to the transform of this specific game object. Also the 'new' operator needs to be applied to the Vector3, not to the result. So the line should be:
clone.rigidbody.velocity = transform.TransformDirection(new Vector3(0,0, 2));
Note you can do the same thing this way:
clone.rigidbody.velocity = transform.forward * 2.0f;