Hi Everyone,
I’ve spent about half a day trying to get my head round this and i’m not having too much luck, essentially what I want to do is play an animation and then once the animation has finished create a flat disk shaped object infront of the current player, the code I have is as follows, please see my comments below for a list of problems:
Note this is cut down code to make the example easy.
static int idleState = Animator.StringToHash("Base Layer.idle");
static int portalState = Animator.StringToHash("Base Layer.Portal");
private RenderTexture portal_texture = Resources.Load("Portal") as RenderTexture;
void Start () {
portal_texture = Resources.Load("Portal") as RenderTexture;
anim = GetComponent<Animator>();
if(anim.layerCount ==2){
anim.SetLayerWeight(1, 1);
}
}
if(Input.GetKey("p")){
anim.SetBool("cast_portal", true);
}
if(Input.GetKeyUp("p")){
sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
sphere.transform.position = transform.TransformPoint(Vector3.zero);
sphere.transform.localScale = new Vector3(3,3,1);
Vector3 temp = sphere.transform.localScale;
temp.x = (sphere.transform.localScale.x + 12.0f) * 0.5f;
sphere.transform.localScale = temp;
sphere.renderer.material.mainTexture = portal_texture;
}
}
Problems
-
The render texture doesn’t appear on the object
-
I need to have the object appear about 10 meters infront of where the character is facing, note i’m using a third person controller so camera position won’t cut it.
-
How come in the inspector I can set any of the scaling options to 0.001 but if I try it in vector3 it throws an exception when compiling?
-
Where do I need to put this code so it only adds the sphere once the animation has finished?
I only started with unity this week so i’m probably missing something very obvious, i’m just having a bit of a brain freeze so any help would be greatly appreciated.
Thanks
Marc