Trees
This commit is contained in:
@@ -15,11 +15,16 @@ public class GameManager : MonoBehaviour
|
||||
public float StopTime = 0.1f;
|
||||
|
||||
public float curVelocity;
|
||||
public float forceMultiplier;
|
||||
public Transform ballProjection;
|
||||
public float ballProjectionScaleMin, ballProjectionScaleMax;
|
||||
|
||||
void Start()
|
||||
{
|
||||
camTargetPos = ball.transform.position;
|
||||
}
|
||||
float stopCooldown = 0;
|
||||
|
||||
void FixedUpdate(){
|
||||
curVelocity = ball.velocity.magnitude;
|
||||
ball.velocity = Vector2.Lerp(ball.velocity, new Vector2(0, ball.velocity.y), BallFriction);
|
||||
@@ -47,6 +52,7 @@ public class GameManager : MonoBehaviour
|
||||
bool dragging = false;
|
||||
Vector2 startPos;
|
||||
public void OnMouseDown(BaseEventData e){
|
||||
if(ball.simulated){return;}
|
||||
PointerEventData ped = (PointerEventData) e as PointerEventData;
|
||||
|
||||
startPos = ped.position;
|
||||
@@ -54,18 +60,35 @@ public class GameManager : MonoBehaviour
|
||||
}
|
||||
|
||||
public void OnMouseUp(BaseEventData e){
|
||||
|
||||
PointerEventData ped = (PointerEventData) e as PointerEventData;
|
||||
if(dragging){
|
||||
Vector2 v = (ped.position-startPos)/inputSensitivity;
|
||||
Vector2 v = ((ped.position-startPos)/inputSensitivity);
|
||||
if(v.magnitude > 1){v = v.normalized;}
|
||||
stopCooldown=0;
|
||||
|
||||
ball.simulated=true;
|
||||
ball.AddForce(-v);
|
||||
ball.AddForce(-v * forceMultiplier);
|
||||
}
|
||||
dragging = false;
|
||||
ballProjection.position = Vector3.zero;
|
||||
}
|
||||
|
||||
public void OnMouseDrag(BaseEventData e){
|
||||
if(ball.simulated){return;}
|
||||
|
||||
ballProjection.position = ball.position;
|
||||
PointerEventData ped = (PointerEventData) e as PointerEventData;
|
||||
Vector2 v = ((ped.position-startPos)/inputSensitivity);
|
||||
Debug.Log(v.magnitude);
|
||||
|
||||
if(v.magnitude > 1){v = v.normalized;}
|
||||
|
||||
Vector3 direction = (ped.position - startPos).normalized;
|
||||
float rot_z = Mathf.Atan2(direction.y,direction.x) * Mathf.Rad2Deg;
|
||||
ballProjection.rotation = Quaternion.Euler(0,0,rot_z+180);
|
||||
|
||||
float scaleDiff = ballProjectionScaleMax - ballProjectionScaleMin;
|
||||
ballProjection.GetChild(0).localScale = new Vector3(ballProjection.GetChild(0).localScale.x,ballProjectionScaleMin + (scaleDiff*v.magnitude));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ public class LevelGenerator : MonoBehaviour
|
||||
|
||||
|
||||
public GameObject flagPrefab;
|
||||
public GameObject treePrefab;
|
||||
|
||||
|
||||
public int GoalDistance= 10;
|
||||
@@ -43,6 +44,18 @@ public class LevelGenerator : MonoBehaviour
|
||||
// spriteShapeController.spline.InsertPointAt(i, points[i]);
|
||||
InsertNewPoint(points[i]);
|
||||
|
||||
|
||||
if(Random.Range(0f,1f) > 0.5f){
|
||||
Vector2 newTreePosition = points[i];
|
||||
|
||||
Vector3 diff = points[i]-points[i-1];
|
||||
Vector2 newTreePosition2 = points[i-1] + (diff/2f);
|
||||
Debug.Log($"{points[i-1]} + {points[i]} - {points[i-1]} / 0.5f | diff = {diff}");
|
||||
GameObject newTree = Instantiate(treePrefab, newTreePosition2, Quaternion.identity);
|
||||
newTree.transform.localScale = Vector3.one * Random.Range(0.75f, 1.1f);
|
||||
}
|
||||
|
||||
|
||||
if(i % GoalDistance == 0){
|
||||
InsertNewPoint(points[i] + new Vector3(0, -1f));
|
||||
InsertNewPoint(points[i] + new Vector3(1f, -1f));
|
||||
@@ -62,7 +75,10 @@ public class LevelGenerator : MonoBehaviour
|
||||
|
||||
|
||||
void InsertNewPoint(Vector3 point){
|
||||
spriteShapeController.spline.InsertPointAt(spriteShapeController.spline.GetPointCount(), point);
|
||||
int index= spriteShapeController.spline.GetPointCount();
|
||||
spriteShapeController.spline.InsertPointAt(index, point);
|
||||
spriteShapeController.spline.SetLeftTangent(index, Vector3.zero);
|
||||
spriteShapeController.spline.SetTangentMode(index, ShapeTangentMode.Broken);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user