Creating a textured object infront of the current character

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

  1. The render texture doesn’t appear on the object

  2. 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.

  3. 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?

  4. 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

Hi.
I don’t know how to detect the end of an animation maybe with this. But I think create your flat disc shaped object in front of the player can be easily resolve. You can design the object in the unity editor and create a prefab. It had to be in a labeled “Resources” directory. then with this function :

Instanciate(Resources.Load("/yourPrefab", Vector3, Quaternion));

you can create your disc in runtime, define its position and its rotation. Here the documentation of this method.

I hope this was helpfull. Good luck.

sorry for my english