Creating a Shield

Hi, I’m currently working on making a Hack 'n Slash, and I’m relatively new to Unity and C#, and I was hoping someone would be able to help me create a shield for my character (that could hopefully be used for the enemy as well).

I’ve been using tons of tutorials and books, but I can’t seem to figure out how to create a shield for the player. In this case when the player presses or holds the right mouse button the player would block the enemies attacks. So if anyone could help me out on creating the shield or send me a tutorial on how to do it, I’ll be grateful. Thanks in advance!

This website is for scripting help, are you talking about creating the model asset of a shield?

Try the unity forum

No I’m talking about creating the code for the player to block. When the player is holding down the button it’ll protect him completely from all hits. He’ll still be able to move but not attack.

well, if you could try this:

var reflectivePower : float;
private var active : boolean;
function Update() {
  if(Input.GetMouseButtonDown(0)) {
    active = true;
  }
  renderer.enabled = active;
}
function OnTriggerEnter(col : Collider) {
  if(active) {
    var dir : Vector3 = col.gameObject.rigidbody.velocity;
    dir = -dir;
    col.gameObject.rigidbody.velocity = dir * reflectivePower;

  }
}

it will reflect all rigid bodies that hit your shield object, which needs to be a trigger.