Hello,
I am trying to create a capsule at run time in my script that will shoot off of my player. However all of my players are 2D sprites, and the capsule is a 3D object. When I remove the 3D components in the script it works fine, but adding the 2D components wont work. I tried googling the issue but I could not find what was wrong with my script. I have tried adding 2D components onto a 3D object via the inspector in unity and that works. I am not sure what the issue is.
Thanks for any help in advanced!
GameObject capsule = GameObject.CreatePrimitive(PrimitiveType.Capsule);
capsule.transform.localScale = new Vector3 (.1f, .1f, .1f); // need to make or bullet not gigantic
if(tag % 2 == 0)
{
Blue = GameObject.FindWithTag (tag.ToString ());
capsule.transform.position = Blue.transform.position;
}
else
{
Red = GameObject.FindWithTag (tag.ToString ());
capsule.transform.position = Red.transform.position;
}
Vector2 movement = new Vector2 (-1, 0);
//need to convert capsule into a 2d object so that it will interact with the rest of the game
//we need to convert the capsule to a 2d object so that it will interact with the rest of our game
//UnityEngine.Object.Destroy(capsule.GetComponent<Rigidbody>());
//UnityEngine.Object.Destroy(capsule.GetComponent<CapsuleCollider>());
//capsule.AddComponent<Rigidbody2D>();
//capsule.AddComponent<BoxCollider2D>();
//capsule.rigidbody2D.velocity = movement * speed;
}