Estou com duvida se uso for ou se tem como usar em uma void.
4 participantes
Página 1 de 1
Estou com duvida se uso for ou se tem como usar em uma void.
- Código:
using System.Collections;[size=14][/size]
using System.Collections.Generic;[size=14][/size]
using UnityEngine;[size=14][/size]
[size=14][/size]
[size=14][/size]
[size=14][/size]
public class atack : MonoBehaviour[size=14][/size]
{[size=14][/size]
public Transform background;[size=14][/size]
private Touch t;[size=14][/size]
private Vector2 startpos;[size=14][/size]
public Transform Player;[size=14][/size]
public Transform FirePoint;[size=14][/size]
public GameObject bulletPref;[size=14][/size]
public float speedforce = 20;[size=14][/size]
[size=14][/size]
[size=14][/size]
Vector2 dist;[size=14][/size]
void Start()[size=14][/size]
[size=14][/size]
[size=14][/size]
{[size=14][/size]
t = new Touch{fingerId = -1};[size=14][/size]
[size=14][/size]
[size=14][/size]
}[size=14][/size]
[size=14][/size]
// Update is called once per frame[size=14][/size]
void Update()[size=14][/size]
{[size=14][/size]
[size=14][/size]
if(Input.touchCount > 0)[size=14][/size]
{[size=14][/size]
[size=14][/size]
for(int a = 0; a < Input.touchCount; a ++){[size=14][/size]
if(t.fingerId == -1){[size=14][/size]
if(Input.GetTouch(a).position.x > Screen.width/2 && Input.GetTouch(a).position.y < Screen.height / 2){[size=14][/size]
t = Input.GetTouch(a);[size=14][/size]
startpos = t.position;[size=14][/size]
background.position = startpos; [size=14][/size]
}[size=14][/size]
}else{[size=14][/size]
if(Input.GetTouch(a).fingerId == t.fingerId){[size=14][/size]
t = Input.GetTouch(a);[size=14][/size]
}[size=14][/size]
}[size=14][/size]
}[size=14][/size]
if(t.fingerId != -1){[size=14][/size]
if(t.phase == TouchPhase.Canceled || t.phase == TouchPhase.Ended){[size=14][/size]
t = new Touch{fingerId = -1};[size=14][/size]
[size=14][/size]
[size=14][/size]
}else{[size=14][/size]
dist = t.position - startpos;[size=14][/size]
transform.position = startpos + Vector2.ClampMagnitude(dist,70);[size=14][/size]
Player.up = Player.position + (Vector3)dist;[size=14][/size]
[size=14][/size]
shoot();[size=14][/size]
[size=14][/size]
}[size=14][/size]
[size=14][/size]
}[size=14][/size]
}[size=14][/size]
if(t.fingerId == -1){[size=14][/size]
transform.position = Vector2.MoveTowards(transform.position,startpos,5);[size=14][/size]
}[size=14][/size]
}[size=14][/size]
public void shoot(){[size=14][/size]
GameObject bullet = Instantiate(bulletPref, FirePoint.position, FirePoint.rotation);[size=14][/size]
Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();[size=14][/size]
rb.AddForce(FirePoint.up * speedforce, ForceMode2D.Impulse);[size=14][/size]
[size=14][/size]
}
quando toco o void shoot ativa so que spawna ate eu tirar o dedo
e isso atrapalha no desenvolvimento queria saber como concertar
joaoguil3- Iniciante
- PONTOS : 1870
REPUTAÇÃO : 3
Respeito as regras :
Re: Estou com duvida se uso for ou se tem como usar em uma void.
Boa noite, to meio sem tempo para "traduzir" o script agora, mas aconselho arrumar o script removendo os codigos desnecessários, facilita no entendimento da questão
Re: Estou com duvida se uso for ou se tem como usar em uma void.
Código limpo:
- Código:
using System.Collections.Generic;
using System.Collections;
using UnityEngine;
public class atack : MonoBehaviour
{
public Transform background;
private Touch t;
private Vector2 startpos;
public Transform Player;
public Transform FirePoint;
public GameObject bulletPref;
public float speedforce = 20;
Vector2 dist;
private void Start() => t = new Touch { fingerId = -1 };
private void Update()
{
if (Input.touchCount > 0)
{
for (int a = 0; a < Input.touchCount; a++)
{
if (t.fingerId == -1)
{
if (Input.GetTouch(a).position.x > Screen.width / 2 && Input.GetTouch(a).position.y < Screen.height / 2)
{
t = Input.GetTouch(a);
startpos = t.position;
background.position = startpos;
}
}
else
{
if (Input.GetTouch(a).fingerId == t.fingerId)
{
t = Input.GetTouch(a);
}
}
}
if (t.fingerId != -1)
{
if (t.phase == TouchPhase.Canceled || t.phase == TouchPhase.Ended)
{
t = new Touch { fingerId = -1 };
}
else
{
dist = t.position - startpos;
transform.position = startpos + Vector2.ClampMagnitude(dist, 70);
Player.up = Player.position + (Vector3)dist;
shoot();
}
}
}
if (t.fingerId == -1)
{
transform.position = Vector2.MoveTowards(transform.position, startpos, 5);
}
}
public void shoot()
{
GameObject bullet = Instantiate(bulletPref, FirePoint.position, FirePoint.rotation);
Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
rb.AddForce(FirePoint.up * speedforce, ForceMode2D.Impulse);
}
}
SteveRogers- Instrutor
- PONTOS : 2725
REPUTAÇÃO : 156
Respeito as regras :
Re: Estou com duvida se uso for ou se tem como usar em uma void.
Pelo que vi no script você pega uma área da tela via código, certo? você pode usar um InputTouchField, básicamente você iria usar um Painel na ui para detectar o touch.
Segue esse vídeo, ele te da um Script com exemplo de Touchfield, é bem fácil de implementar, assim você pode desativar o Painel, e não vai atrapalhar no desenvolvimento:
Segue esse vídeo, ele te da um Script com exemplo de Touchfield, é bem fácil de implementar, assim você pode desativar o Painel, e não vai atrapalhar no desenvolvimento:
Charlesoff- MembroAvançado
- PONTOS : 1833
REPUTAÇÃO : 40
Áreas de atuação : Game dev
Respeito as regras :
Tópicos semelhantes
» dúvida com void Start () ou void Update? qual usar !!! #HELP
» Dúvida com void OnTriggerEnter
» [RESOLVIDO]Duvida com butao UI para ativar Void
» [Duvida] Como chamar uma void criada por mim, apenas em determinados momentos.
» Void OntriggerEnter e Void Ontriggerexit
» Dúvida com void OnTriggerEnter
» [RESOLVIDO]Duvida com butao UI para ativar Void
» [Duvida] Como chamar uma void criada por mim, apenas em determinados momentos.
» Void OntriggerEnter e Void Ontriggerexit
Página 1 de 1
Permissões neste sub-fórum
Não podes responder a tópicos