- Home /
swapping meshes
im making a fighting game and when a character punches or something instead of them moving i want it to be instant like in retro fighting games, so instead of having an animation i would just swap the mesh (the animations are broken in my 3ds max anyway). i could just delete the old mesh and instantiate a new one but there must be an easier way so does anyone know it?
Answer by ScroodgeM · Aug 13, 2012 at 06:55 PM
you can make two or more geometry on each other a simple disable all renderers except one. whenever you need just re-enable them all to another combination to get another renderer enabled
too late i already wrote the script lol
var punchControl : String;
var jumpControl : String;
var kickControl : String;
var leftControl : String;
var rightControl : String;
var blockControl : String;
var crouchControl : String;
var canPunch = 1;
var canJump = 1;
var can$$anonymous$$ick = 1;
var health = 100;
var shown$$anonymous$$esh : GameObject;
var idle$$anonymous$$esh : GameObject;
var punch$$anonymous$$esh : GameObject;
var jump$$anonymous$$esh : GameObject;
var jump$$anonymous$$ick$$anonymous$$esh : GameObject;
var crouchPunch$$anonymous$$esh : GameObject;
var block$$anonymous$$esh : GameObject;
var standPos = 1;
var blocking = 0;
var punchDamage = 3
var kickDamage = 5;
var jump$$anonymous$$ickDamage = 6;
var crouchPunchDamage = 4;
var damage$$anonymous$$ultiplier = 1;
function Update () {
if(blocking == 1){
damage$$anonymous$$ultiplier = 0.2;
}
if(blocking == 0){
damage$$anonymous$$ultiplier = 1;
}
if(Input.Get$$anonymous$$eyDown("punchControl")){
if(blocking == 0){
if(canPunch == 1){
if(standPos == 1){
Punch();
}
}
}
if(blocking == 0){
if(canPunch == 1){
if(standPos == 0){
CrouchPunch();
}
}
}
}
if(Input.Get$$anonymous$$eyDown("kickControl")){
if(blocking == 0){
if(can$$anonymous$$ick == 1){
if(standPos == 1){
$$anonymous$$ick();
}
}
if(can$$anonymous$$ick == 1){
if(standPos == 2){
Jump$$anonymous$$ick();
}
}
}
}
if(Input.Get$$anonymous$$ey("leftControl")){
if(blocking == 0){
$$anonymous$$oveLeft();
}
}
if(Input.Get$$anonymous$$ey("rightControl")){
if(blocking == 0){
$$anonymous$$oveRight();
}
}
if(Input.Get$$anonymous$$eyDown("jumpControl")){
if(blocking == 0){
if(canJump == 1){
if(standPos != 2){
Jump();
}
}
}
}
if(Input.Get$$anonymous$$eyDown("crouchControl")){
if(blocking == 0){
if(standPos != 2){
CrouchDown();
}
}
}
if(Input.Get$$anonymous$$eyUp("crouchControl")){
if(blocking == 0){
if(standPos == 0){
crouchUp();
}
}
}
if(Input.Get$$anonymous$$eyDown("blockControl")){
if(standPos == 1){
if(can$$anonymous$$ick == 1){
if(canPunch == 1){
if(canJump == 1){
BlockDown();
}
}
}
}
}
if(Input.Get$$anonymous$$eyUp("blockControl")){
if(blocking == 1){
BlockUp();
}
}
}
function Punch () {
canPunch = 0;
Destroy(shown$$anonymous$$esh);
shown$$anonymous$$esh = Instantiate(jump$$anonymous$$esh,transform.position,transform.rotation);
Invoke("EndPunch",0.3);
}
function EndPunch () {
Destroy(shown$$anonymous$$esh);
shown$$anonymous$$esh = Instantiate(idle$$anonymous$$esh,transform.position,transform.rotation);
canPunch = 1;
function $$anonymous$$ick () {
can$$anonymous$$ick = 0;
Destroy(shown$$anonymous$$esh);
shown$$anonymous$$esh = Instantiate(kick$$anonymous$$esh,transform.position,transform.rotation);
Invoke("End$$anonymous$$ick",0.5);
}
function End$$anonymous$$ick () {
can$$anonymous$$ick = 1;
Destroy(shown$$anonymous$$esh);
shown$$anonymous$$esh = Instantiate(idle$$anonymous$$esh,transform.position,transform.rotation);
}
function $$anonymous$$oveLeft () {
transform.Translate(Vector3.left * Time.deltaTime * 3);
}
function $$anonymous$$oveRight () {
transform.Translate(Vector3.right * Time.deltaTime * 3);
}
function Jump$$anonymous$$ick () {
can$$anonymous$$ick = 0;
Destroy(shown$$anonymous$$esh);
shown$$anonymous$$esh = Instantiate(jump$$anonymous$$ick$$anonymous$$esh,transform.position,transform.rotation);
Invoke("End$$anonymous$$ick",1);
}
}
function Jump () {
standPos = 2;
Destroy(shown$$anonymous$$esh);
shown$$anonymous$$esh = instantiate(jump$$anonymous$$esh,transform.position,transform.rotation);
Invoke("EndJump",0.5);
}
function EndJump () {
Destroy(shown$$anonymous$$esh);
shown$$anonymous$$esh = Instantiate(idle$$anonymous$$esh,transform.position,transform.rotation);
}
function CrouchDown () {
standPos = 0;
Destroy(shown$$anonymous$$esh);
shown$$anonymous$$esh = Instantiate(crouch$$anonymous$$esh,transform.position,transform.rotation);
}
function CrouchUp () {
standPos = 1;
Destroy(shown$$anonymous$$esh);
shown$$anonymous$$esh = Instantiate(idle$$anonymous$$esh,transform.position,transform.rotation);
}
}
function BlockDown () {
Destroy(shown$$anonymous$$esh);
shown$$anonymous$$esh = Instantiate(block$$anonymous$$esh,transform.position,transform.rotation);
blocking = 1;
canPunch = 0;
can$$anonymous$$ick = 0;
canJump = 0;
}
function BlockUp () {
Destroy(shown$$anonymous$$esh);
shown$$anonymous$$esh = Instantiate(idle$$anonymous$$esh,transform.position,transform.rotation);
blocking = 0;
canPunch = 1;
can$$anonymous$$ick = 1;
canJump = 1;
}
function CrouchPunch () {
Destroy(shown$$anonymous$$esh);
shown$$anonymous$$esh = Instantiate(crouchPunch$$anonymous$$esh,transform.position,transform.rotation);
canPunch = 0;
Invoke("EndPunch",0.3);
}
function OnCollisionEnter (something : Collider) {
if(something.Collider.tag == "punch"){
health -= punchDamage * damage$$anonymous$$ultiplier;
}
else
if(something.Collider.tag == "kick"){
health -= kickDamage * damage$$anonymous$$ultiplier;
}
else
if(something.Collider.tag == "jumpkick"){
health -= jump$$anonymous$$ickDamage * damage$$anonymous$$ultiplier;
}
else
if(something.Collider.tag == "crouchpunch"){
health -= crouchPunchDamage * damage$$anonymous$$ultiplier;
Your answer
![](https://koobas.hobune.stream/wayback/20220613075604im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I keep separate meshes for a character when I import it into Unity? 1 Answer
translating an accessory from source mesh to a targeted mesh 0 Answers
Why is my animated with Mecanim character (enemy) not visible in game (play) mode? 1 Answer
Character Animation Pose Mesh,Animated Pose Mesh 0 Answers
Offset transformer when I import mesh? 0 Answers