- Home /
Yet Another Bullet Decal Problem
Ive ran through two pages, on this problem, but the solution is the decal system that is 95$ or not being sold anymore. Ive cobbled some code together but the decals are not being painted so to speak. Note i am using particles for the decals rather than textures. So, why would my particle bullet decals not be painted.
public class SCAR : MonoBehaviour
{
Vector3 point;
public Rigidbody b_556mm;//the rigid body containter for an object for the bullet
public Transform Spawn;//this is the location the bullet will spwan from
public float speed = 5.0f;//bullets speed
public int damage = 75;//damage by the weapon
public GameObject decalHitWall;//the particle to be used as bullet decal
RaycastHit hit = new RaycastHit();
Ray hitray = new Ray();
public float baseFOV;
float fireRate = 0.15f;
float lastShot = -10.0f;
public int bullets = 30;
int bulletsDummy;
public int mag = 3;
public Font Tinker;//font used for the GUI render
// Use this for initialization
void Start ()
{
baseFOV = Camera.main.fieldOfView;
}
// Update is called once per frame
void Update ()
{
bulletsDummy = bullets;
hitray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
//Fire Mechanisms.
if(Input.GetKey(KeyCode.Mouse0))
{
if(bullets > 0 && mag > 0)
{
if(Time.time > fireRate + lastShot)
{
if (Physics.Raycast(hitray, out hit, 1000.0f))
{
point = hit.point;
Spawn.transform.LookAt(point);
//Bullet prefabs go here
GameObject decalClone = (GameObject)Instantiate(decalHitWall, hit.point, Quaternion.LookRotation(Vector3.up, hit.normal));
Destroy(decalClone.gameObject, 30);
Debug.DrawRay(hitray.origin, hitray.direction, Color.blue, 100, true);
Health enemyHealth = hit.transform.GetComponent<Health>();
if(enemyHealth != null)
{
enemyHealth.Damage(damage);
}
print (hit.transform.name); // logs it into the console
}
Rigidbody instance = (Rigidbody)Instantiate(b_556mm, Spawn.position, Spawn.rotation);
instance.AddForce(transform.forward * speed);
GetComponent<AudioSource>().Play();
lastShot = Time.time;
Destroy(instance.gameObject, 1);//destroy the rigidboy to save on memmory after a second.
bullets--;
//print("bullets left: " + bullets);
}//end time if
// print(Value(bullets, mag));
if(bullets == 0)
{
mag--;
//print("mag left: " + mag);
bullets = 30;
}
}//end bullets nad mag if
}//end input if
//Zoom Mechanism
if(Input.GetButton ("Fire2"))
{
Camera.main.fieldOfView = 25;
}
else
{
Camera.main.fieldOfView = baseFOV;
}
}
void OnGUI()
{
GUIStyle TinkerFont = new GUIStyle();
TinkerFont.font = Tinker;//this works, changes the hud to Tinker Font.
TinkerFont.fontSize = 24;
TinkerFont.normal.textColor = Color.red;
GUI.Label(new Rect(900,500, 75,35),Value(bullets, mag), TinkerFont);
}
public string Value(int a, int b)
{
string total;
return total = bullets + " / " + mag;
}
}//end class
Is the clone of the particle prefab instantiated correctly? If it's there, but not visible, then it's a problem with the settings of the ParticleSystem component.
I believe so. Granted i took that line and adjusted it a bit. I have no particle system component attached. I am just calling the particle as a game object. I dont think that i a problem. Ive done it before.
Just to be clear. The Prefab "decalHitWall" has a ParticleObject component on it and if dragged into the scene manually, it will play correctly and show the bullet mark particle, right?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Jagged Array 2 Answers
Avatar constructor returns null 1 Answer