Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I am fairly new to programming and I am trying to learn by making a simple game. I watched to different videos on ray cast shooting and one of them has code for bullet hole decals that I wanted to add to the other one but I was to sure, about how I would go about doing that. I would really appreciate any help than anyone can give with this problem, as it would really help me lean some more about programming. The first set of code is the one I want to insert the other code into.

Thanks, Nova

#pragma strict

var Effect : Transform;
var TheDammage = 100;

function Update () {
	
	var hit : RaycastHit;
	var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0)); 
	
	if (Input.GetMouseButtonDown(0))
	{
		if (Physics.Raycast (ray, hit, 100))
		{
			var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal));
			Destroy(particleClone.gameObject, 2);
			hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
		}
	}
	
}

var bulletTex : GameObject[]; // creates an array to use random textures of bullet holes
 
function Update () {
 
   var fwd = transform.TransformDirection(Vector3.forward); //casts our raycast in the forward direction
 
   var hit : RaycastHit;
 
   Debug.DrawRay(transform.position, fwd * 10, Color.green); //drays our raycast and gives it a green color and a length of 10 meters
 
if(Input.GetButtonDown ("Fire1") && Physics.Raycast(transform.position, fwd, hit, 10)){ //when we left click and our raycast hits something
         Instantiate(bulletTex[Random.Range(0,3)], hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal)); //then we'll instantiate a random bullet hole texture from our array and apply it where we click and adjust// the position and rotation of textures to match the object being hit
}

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.