static public void Main() { petanim p = delegate(string mypet){ Console.WriteLine("My favorite pet is: {0}", mypet); }; p("Dog"); }
public void UpdateViewMatrix(float maxDistance = 500.0f) { for (int i = 0; i < verticalResolution; i++) { for (int j = 0; j < horizontalResolution; j++) { RaycastHit hitinfo; if (Physics.Raycast(raysMatrix[i, j], out hitinfo, visionMaxDistance)) { //Debug.DrawRay(raysMatrix[i,j].origin, raysMatrix[i,j].direction * visionMaxDistance, Color.yellow); GameObject gobj = hitinfo.collider.gameObject; petanim other = gobj.GetComponent <petanim>(); string objname = gobj.name; string objtag = gobj.tag; if (objtag == "gate") { viewMatrix[i, j] = 100; } else if (objtag == "wall") { viewMatrix[i, j] = 6; } else if (objtag == "action") { if (objname == "Action1") { viewMatrix[i, j] = 170; } else if (objname == "Action2") { viewMatrix[i, j] = 255; } else if (objname == "Action3") { viewMatrix[i, j] = 255; } else { viewMatrix[i, j] = 170; } } else if (objtag == "ground") { viewMatrix[i, j] = 30; } } else { viewMatrix[i, j] = 0; } } } }
public void UpdateViewMatrix(float maxDistance = 500.0f) { for (int i = 0; i < verticalResolution; i++) { for (int j = 0; j < horizontalResolution; j++) { RaycastHit hitinfo; if (Physics.Raycast(raysMatrix[i, j], out hitinfo, visionMaxDistance)) { //Debug.DrawRay(raysMatrix[i,j].origin, raysMatrix[i,j].direction * visionMaxDistance, Color.yellow); GameObject gobj = hitinfo.collider.gameObject; petanim other = gobj.GetComponent <petanim>(); string objname = gobj.name; if (objname == "Terrain") { viewMatrix[i, j] = 1; } else { string objtag = gobj.tag; if (objtag == "eating") { viewMatrix[i, j] = 4; } else if (objname.StartsWith("block")) { viewMatrix[i, j] = 3; } else if (objtag == "wall") { viewMatrix[i, j] = 2; } else if (objtag == "agent") { int code = int.Parse(objname.Split('_')[1]); viewMatrix[i, j] = code + 10 + (int)other.Signal * 10; //viewMatrix[i, j] = code + 10; } else { viewMatrix[i, j] = 0; } } } else { viewMatrix[i, j] = 0; } } } }
static public void Main() { // The 'fav' variable is assigned to the "Rabbit" string. string fav = "Rabbit"; // Using the delegate petanim from above, an anonymous // method that has one parameter is created. petanim p = delegate(string mypet) { Console.WriteLine("My favorite pet is {0}.", mypet); // The outer variable, 'fav', can be accessed // by the anonymous method. Console.WriteLine("And I like {0} also.", fav); }; // The unnamed method is invoked here, assigning "Dog" // string to the 'mypet' variable. p("Dog"); }
/// <summary> /// OnCollisionEnter is called when this collider/rigidbody has begun /// touching another rigidbody/collider. /// </summary> /// <param name="other">The Collision data associated with this collision.</param> void OnCollisionStay(Collision other) { if (IsDone()) { return; } string objtag = other.gameObject.tag; string objname = other.gameObject.name; if (objtag == "eating") { touched_id = 4; //Debug.Log("Signal " + signal); if (signal > 0) { energy += eggValue; Destroy(other.gameObject); manager.DestroyEgg(); } } else if (other.gameObject.tag == "agent") { int code = int.Parse(other.gameObject.name.Split('_')[1]); petanim anim = other.gameObject.GetComponent <petanim>(); touched_id = code + 10; if (!energyGainLocker) { energyGainLocker = true; if (signal > 0 && anim.signal > 0) { this.energy += 10; } else if (signal > 0 && anim.signal == 0) { this.energy -= 10; } else if (signal == 0 && anim.signal > 0) { this.energy += 10; } else if (signal == 0 && anim.signal == 0) { this.energy -= 5; } } } else if (objname.StartsWith("block")) { touched_id = 3; } else if (objtag == "wall") { touched_id = 2; } else if (objname == "Terrain") { touched_id = 1; } else { touched_id = 0; } if (other.gameObject.tag == "ground") { foreach (ContactPoint contact in other.contacts) { if (Vector3.Distance(contact.point, feet.transform.position) < 2.0f) { onGround = true; break; } //print(contact.thisCollider.name + " hit " + contact.otherCollider.name); // Visualize the contact point //Debug.DrawRay(contact.point, contact.normal, Color.white); } } }