using System.Collections;
using UnityEngine.Debug;
using UnityEngine;
public class JoyStickAttack : MonoBehaviour
{
private Vector2 startingPoint;
private int leftTouch = 99;
// Update is called once per frame
void Update()
{
// Identifying if the button was just pressed or pressed or not pressed
int i = 0;
while (i < Input.TouchCount)
Touch t = Input.GetTouch(i);
Vector2 touchPos = getTouchPosition(t.position) * -1;
if(t.phase == TouchPhase.Began)
{
if(t.position.x > ScreenWidth / 2)
{
shootBullet();
}
else
{
leftTouch = t.fingerId;
startingPoint = touchPos;
}
}else if(t.phase == TouchPhase.Moved)
{
}else if(t.phase == TouchPhase.Ended)
{
}
}
//Identifyies where is the finger touching
Vector2 getTouchPosition(Vector2 touchPosition)
{
return GetComponent<Camera>().ScreenToWorldPoint(new Vector3(touchPosition.x, touchPostion.y, transform.position.z));
}
void CharacterMovement(Vector2 direction)
{
}
void shootBullet()
{
}
}
Get rid of using UnityEngine.Debug
.
the error is:
error CS0138: A ‘using namespace’ directive can only be applied to namespaces; ‘Debug’ is a type not a namespace. Consider a ‘using static’ directive instead
i tried it gave me 5 new errors
it gave me the errors
error CS0117: ‘Input’ does not contain a definition for ‘TouchCount’
error CS1023: Embedded statement cannot be a declaration or labeled statement
error CS0103: The name ‘t’ does not exist in the current context
The name ‘ScreenWidth’ does not exist in the current context
error CS0103: The name ‘touchPostion’ does not exist in the current context
Should be “touchCount”, with a lowercase ‘t’.
https://docs.unity3d.com/ScriptReference/Input-touchCount.html
You’re missing curly braces in your while-loop statement.
It looks like you’re also creating an endless loop as well, since you’re not incrementing the i
variable that the while-loop’s condition is checking.
Why not use a for-loop instead?
for(int i = 0; i < Input.touchCount; i++)
{
Touch t = Input.GetTouch(i);
//etc...
}
You haven’t declared a “ScreenWidth” variable anywhere in your script. You’re also using a “TouchPhase” variable, but this variable hasn’t been declared anywhere either.
You misspelled “touchPosition”.
oops btw thanks bro