void OnHit() { count++; // if (currentLine.transform.position.y < 1) // down -= 0.05f; scrollDownSpeed *= 1.5f; // currentLine.transform.SetParent(path.Peek().transform);// change currentLine.Follow(path.Peek().transform.GetComponent <LineBehaviour>().Target.transform); // Destroy(currentLine.gameObject, 5); currentLine = path.Dequeue(); currentLine.Hit(path.Peek()); direction = currentLine.DistanceBetween(path.Peek()) < 0 ? 1 : -1; SpawnLine(linePrefabs[Random.Range(0, difficulty)]); score += 1 + perfectCombo; if (score % 30 == 0 && difficulty < linePrefabs.Count) { difficulty++; } if (score > highScore) { analyticsManager.HighScoreEvent(score); PlayerPrefs.SetInt("Highscore", score); } ui.UpdateScore(score); ui.UpdateCombo(perfectCombo); speed += speedModifier; }
void Update() { if (Input.GetMouseButtonDown(0)) { GameObject line = Instantiate(linePrefab); activeLine = line.GetComponent <LineBehaviour> (); coolOff = false; } if (activeLine != null && inkBottle.value > 1 && !coolOff) { Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); activeLine.updateLine(mousePosition); inkBottle.value -= decreasingSpeed * Time.deltaTime; } /*else * { * if (inkBottle.value < inkBottle.maxValue && coolOff) * inkBottle.value += increasingSpeed * Time.deltaTime; * }*/ if (Input.GetMouseButtonUp(0)) { activeLine = null; coolOff = false; StartCoroutine(coolOffStarter()); Camera.main.GetComponent <CameraBehaviour>().cameraFollow(); if (shipRb.isKinematic) { shipRb.bodyType = RigidbodyType2D.Dynamic; } } }
private void RemoveLine(GeoLine geoLine) { LineBehaviour lineBehaviour = lineMap[geoLine]; Destroy(lineBehaviour.gameObject); lineMap.Remove(geoLine); }
public virtual void Hit(LineBehaviour next) { if (lastHitLine is LineWithWalls) { LineWithWalls w = (LineWithWalls)lastHitLine; w.HideWalls(); } var col = GoodParticle.colorOverLifetime; col.enabled = true; Gradient grad = new Gradient(); grad.SetKeys(new GradientColorKey[] { new GradientColorKey(currentColor, 0.5f), new GradientColorKey(next.currentColor, 1.0f) }, new GradientAlphaKey[] { new GradientAlphaKey(1f, 0.0f), new GradientAlphaKey(0.0f, 1.0f) }); col.color = grad; GoodParticle.Play(); // Debug.Log( lastHitLine.transform.name + " => " + this.transform.name); // this.Part.gameObject.SetActive(true); // var dis = this.Target.transform.position.x - lastHitLine.Target.transform.position.x; // Debug.Log(dis); // this.Part.transform.localScale = new Vector3(Mathf.Abs(dis), 1, 1); // this.Part.transform.Translate((dis > 0 ? Vector2.right : Vector2.left) * (1-Mathf.Abs(dis))/2); // this.Target.transform.localScale = new Vector3(1-Mathf.Abs(dis), 1, 1); // this.Target.transform.Translate((dis < 0 ? Vector2.right : Vector2.left) * Mathf.Abs(dis)/2); lastHitLine = this; }
//目前用不到 public void ChangeLine(Vector3[] positions) { Function func = (Function)this.geometry; GameObject line = GameObject.Find("3D/Geometry/Line/line " + (func.Getindex() - 1).ToString()); LineBehaviour lineBehaviour = line.GetComponent <LineBehaviour>(); lineBehaviour.ChangeData(positions); }
// float IsClose(Vector3 a, Vector3 b) // { // return Mathf.Abs(a.x - b.x); // } public void Initialize() { canPlay = true; for (int i = -1; i < 10; i++) { SpawnLine(linePrefabs[0], false); } currentLine = path.Dequeue(); }
public virtual void Activate(float spawnHeight, Color currentColor) { Vector3 spawnPos = Vector3.up * spawnHeight; this.transform.localPosition = spawnPos; this.Target.transform.localPosition = Vector3.left * Random.Range(-bounds, bounds); Target.color = currentColor; this.currentColor = currentColor; // GameManager.instance.FixLine(this.transform); // if (lastSpawnLine && IsClose(lastSpawnLine) < 1f) // { // float d = DistanceBetween(lastSpawnLine); // Debug.Log(d); // transform.Translate(Vector2.right * d); // // } // // if (transform.position.x < 0) // // { // // transform.Translate(Vector3.right*2); // // // transform.position = new Vector3(transform.position.x * -1, transform.position.y, transform.position.z); // // } // // else // // { // // transform.Translate(Vector3.left*2); // // // transform.Translate(Vector3.left * (Random.value < 0.5f ? 1 : -1)); // // } // } if (lastSpawnLine && IsClose(lastSpawnLine) < 1f) { if (IsClose(Vector3.zero) > 1f) { this.Target.transform.position = new Vector3(this.Target.transform.position.x * -1, this.Target.transform.position.y, this.Target.transform.position.z); } else { this.Target.transform.Translate(Vector3.left * (Random.value < 0.5f ? 1 : -1)); } } lastSpawnLine = this; if (lastHitLine == null) { lastHitLine = this; } }
//generate function line public void AddLine(GeoLine geoLine) { if (!lineMap.ContainsKey(geoLine)) { GameObject planeObject = new GameObject(geoLine.ToString()); planeObject.transform.SetParent(lineWrapper.transform); LineBehaviour lineBehaviour = planeObject.AddComponent <LineBehaviour>(); lineBehaviour.Init(geoLine, geoCamera); lineMap.Add(geoLine, lineBehaviour); elementMap.Add(geoLine, lineBehaviour); HighlightLine(geoLine); } }
public override void Hit(LineBehaviour next) { base.Hit(next); if (left) { leftWall.transform.SetParent(this.transform.parent, true); } if (right) { rightWall.transform.SetParent(this.transform.parent, true); } // rightWall.transform.parent = this.transform.parent; }
public Line(LineBehaviour lineBehaviour) { this.lineBehaviour = lineBehaviour; if (!lineBehaviour.OriginNode || !lineBehaviour.EndNode || !lineBehaviour.CentreNode || !lineBehaviour.CentreNodeActivator) { throw new ArgumentException("Must set nodes on lineBehaviour prefab!", nameof(lineBehaviour)); } centreNodeActivatorCollider = lineBehaviour.CentreNodeActivator.GetComponent <BoxCollider>(); if (centreNodeActivatorCollider == null) { throw new NullReferenceException( $"{nameof(lineBehaviour.CentreNodeActivator)} must have BoxCollider component"); } originNodeCollider = lineBehaviour.OriginNode.GetComponent <Collider>(); if (originNodeCollider == null) { throw new NullReferenceException( $"{nameof(lineBehaviour.OriginNode)} must have collider component"); } endNodeCollider = lineBehaviour.EndNode.GetComponent <Collider>(); if (endNodeCollider == null) { throw new NullReferenceException( $"{nameof(lineBehaviour.EndNode)} must have collider component"); } centreNodeCollider = lineBehaviour.CentreNode.GetComponent <Collider>(); if (centreNodeCollider == null) { throw new NullReferenceException( $"{nameof(lineBehaviour.CentreNode)} must have collider component"); } meshFilter = LineObject.GetComponent <MeshFilter>(); cursor = lineBehaviour.Cursor; }
void Update() { if (Input.GetMouseButtonDown(0)) { Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); line = Instantiate(linePrefab, mousePosition, Quaternion.identity); activeLine = line.GetComponent <LineBehaviour> (); } if (activeLine != null) { Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); activeLine.updateLine(mousePosition); } if (Input.GetMouseButtonUp(0)) { activeLine = null; Destroy(line); } }
void Update() { if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); Vector2 touchPosition = Camera.main.ScreenToWorldPoint(touch.position); if (touch.phase == TouchPhase.Began) { line = Instantiate(linePrefab, touchPosition, Quaternion.identity); activeLine = line.GetComponent <LineBehaviour> (); } else if (touch.phase == TouchPhase.Moved) { activeLine.updateLine(touchPosition); } else if (touch.phase == TouchPhase.Ended) { activeLine = null; Destroy(line); } } }
private void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Corner")) { var corner = other.GetComponent <CornerBehaviour>(); var direction = transform.GetDirectionTo(corner.AnchorPoint); transform.SetParent(corner.AnchorPoint, true); //TODO: Object pooling is not working as it supposed to be //_line = _linePrefab.Spawn(); _line = Instantiate(_linePrefab); _line.Initialize(transform, corner.AnchorPoint); ToggleRotating(true, direction); } else if (other.gameObject.CompareTag("FinishLine")) { StopAll(); Finish?.Invoke(true); } }
void Update() { if (Input.GetMouseButtonDown(0)) { GameObject line = Instantiate(linePrefab); activeLine = line.GetComponent <LineBehaviour> (); } if (activeLine != null) { Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); activeLine.updateLine(mousePosition); } if (Input.GetMouseButtonUp(0)) { activeLine = null; Camera.main.GetComponent <CameraBehaviour>().cameraFollow(); if (shipRb.isKinematic) { shipRb.bodyType = RigidbodyType2D.Dynamic; } } }
private void OnEnable() { parentLine = transform.parent.GetComponent <LineBehaviour>(); }
private void UpdateLine(GeoLine geoLine) { LineBehaviour lineBehaviour = lineMap[geoLine]; //lineBehaviour.SetData(geometry.Line(geoLine)); }
public override void Hit(LineBehaviour next) { base.Hit(next); StopAllCoroutines(); }
public float IsClose(LineBehaviour b) { return(Mathf.Abs(DistanceBetween(b))); }
public float DistanceBetween(LineBehaviour b) { return(this.Target.transform.position.x - b.Target.transform.position.x); }