Question by
scaletta865 · Jun 12, 2020 at 10:01 AM ·
positioncuberoll
Cube a roll .what can I do for integer output?
this is the position of the cube after the roll what can I do for integer output?
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerController : MonoBehaviour
{
// Start is called before the first frame update
public int rollSpeed;
public bool isRolling;
public GameObject scope;
public GameManage gameManage;
// Update is called once per frame
void Start()
{
rollSpeed = 10;
transform.position = new Vector3(0,3,-15);
}
void FixedUpdate()
{
if (transform.position.y < 0.0f)//oyuncunun düsüp düsmedigini kontrol eder
{
//SceneManager.LoadScene("MainMenu");
gameManage.gameOver();
}
if (isRolling)
return;
if (Input.GetKeyDown(KeyCode.W))
{
isRolling = true;
StartCoroutine(Roll(transform.position+ new Vector3(0,-2.5f,2.5f),Vector3.right) );
}
else if (Input.GetKeyDown(KeyCode.S))
{
isRolling = true;
StartCoroutine(Roll(transform.position + new Vector3(0, -2.5f, -2.5f), Vector3.left));
}
else if (Input.GetKeyDown(KeyCode.A))
{
isRolling = true;
StartCoroutine(Roll(transform.position + new Vector3(-2.5f, -2.5f, 0), Vector3.forward));
}
else if (Input.GetKeyDown(KeyCode.D))
{
isRolling = true;
StartCoroutine(Roll(transform.position + new Vector3(2.5f, -2.5f, 0), Vector3.back));
}
}
IEnumerator Roll(Vector3 pivot, Vector3 vec)
{
transform.GetComponent<Rigidbody>().useGravity = false;
for (int i = 0; i < (90/rollSpeed); i++)
{
transform.RotateAround(pivot, vec, rollSpeed);
yield return new WaitForSeconds(0.01F);
}
isRolling = false;
transform.GetComponent<Rigidbody>().useGravity = true;
yield return null;
}
}
pozisyon.png
(3.1 kB)
ekran-alıntısı.png
(4.5 kB)
Comment
Your answer
Follow this Question
Related Questions
How to make a cube tumble to player 0 Answers
How can i make the cube roll 0 Answers
Cube rolling problem (rotation problem) 1 Answer
Roll cuboid does not work properly 1 Answer
Aligning sticky cubes 1 Answer