- Home /
i made a code and the sword doesn't show up...
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class FightMode : MonoBehaviour { public Transform Sword; public Transform player; public int WhichPlayer; //Player 1's sword rotation variables //Up public int Player1UpRotationX; public int Player1UpRotationY; public int Player1UpRotationZ; //Left public int Player1LeftRotationX; public int Player1LeftRotationY; public int Player1LeftRotationZ; //Down public int Player1DownRotationX; public int Player1DownRotationY; public int Player1DownRotationZ; //Right public int Player1RightRotationX; public int Player1RightRotationY; public int Player1RightRotationZ; //Player 2's sword rotaion variables //Up public int Player2UpRotationX; public int Player2UpRotationY; public int Player2UpRotationZ; //Left public int Player2LeftRotationX; public int Player2LeftRotationY; public int Player2LeftRotationZ; //Down public int Player2DownRotationX; public int Player2DownRotationY; public int Player2DownRotationZ; //Right public int Player2RightRotationX; public int Player2RightRotationY; public int Player2RightRotationZ; // Start is called before the first frame update public void AttackMode() { Coop2.AttackMode = 1; }
// Update is called once per frame
public void Update()
{
if (WhichPlayer == 0) // First player's controll over attacking
{
if (Coop2.AttackMode == 1)
{
if (Input.GetKey(KeyCode.Space))
{
//Up
if (Input.GetKey(KeyCode.W))
{
Sword.position = new Vector3(player.position.x, player.position.y, player.position.z);
Sword.rotation = new Quaternion(Player1UpRotationX, Player1UpRotationY, Player1UpRotationZ, Sword.rotation.w);
}
//Left
if (Input.GetKey(KeyCode.A))
{
Sword.position = new Vector3(player.position.x, player.position.y, player.position.z);
Sword.rotation = new Quaternion(Player1LeftRotationX, Player1LeftRotationY, Player1LeftRotationZ, Sword.rotation.w);
}
//Down
if (Input.GetKey(KeyCode.S))
{
Sword.position = new Vector3(player.position.x, player.position.y, player.position.z);
Sword.rotation = new Quaternion(Player1DownRotationX, Player1DownRotationY, Player1DownRotationZ, Sword.rotation.w);
}
//Right
if (Input.GetKey(KeyCode.D))
{
Sword.position = new Vector3(player.position.x, player.position.y, player.position.z);
Sword.rotation = new Quaternion(Player1RightRotationX, Player1RightRotationY, Player1RightRotationZ, Sword.rotation.w);
}
}
}
}
if (WhichPlayer == 1)// Second player's controll over attacking
{
if (Coop2.AttackMode == 1)
{
if (Input.GetKey(KeyCode.RightShift))
{
//Up
if (Input.GetKey(KeyCode.UpArrow))
{
Sword.position = new Vector3(player.position.x, player.position.y, player.position.z);
Sword.rotation = new Quaternion(Player2UpRotationX, Player2UpRotationY, Player2UpRotationZ, Sword.rotation.w);
}
//Left
if (Input.GetKey(KeyCode.LeftArrow))
{
Sword.position = new Vector3(player.position.x, player.position.y, player.position.z);
Sword.rotation = new Quaternion(Player2LeftRotationX, Player2LeftRotationY, Player2LeftRotationZ, Sword.rotation.w);
}
//Down
if (Input.GetKey(KeyCode.DownArrow))
{
Sword.position = new Vector3(player.position.x, player.position.y, player.position.z);
Sword.rotation = new Quaternion(Player2DownRotationX, Player2DownRotationY, Player2DownRotationZ, Sword.rotation.w);
}
//Right
if (Input.GetKey(KeyCode.RightArrow))
{
Sword.position = new Vector3(player.position.x, player.position.y, player.position.z);
Sword.rotation = new Quaternion(Player2RightRotationX, Player2RightRotationY, Player2RightRotationZ, Sword.rotation.w);
}
}
}
}
}
}
the values of the rotations are as follows: Player1/2UpRotation = X:360 Y:0 Z:0 Player1/2downRotation = X:180 Y:0 Z:0 Player1/2LeftRotation = X:90 Y:0 Z:0 Player1/2RightRotation = X:-90 Y:0 Z:0
Answer by dtbrown0801 · Dec 28, 2019 at 01:26 AM
Does it show up in the hierarchy? If it does than I would check if it has an animation (maybe an accident) that changes the position Or if it is a first person the camera settings.
Also maybe the sword's mesh acts like a plain and can not be seen in those values of rotation.
Answer by ryanaalley05 · Jan 09, 2020 at 07:00 AM
Never mind. I already scrapped the idea for a better one thank you!
Your answer
![](https://koobas.hobune.stream/wayback/20220612220600im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Detect if player is left or right of enemy 1 Answer
for fighting what is the script required for movement of the player.? 0 Answers
How to make an AI and Player code for a fighting game similar to tekken or street fighter? 0 Answers
When I want to kill an enemy with a strong attack, the enemy just gets stuck. How do I fix this? 1 Answer